﻿#include "stdafx.h"
#include "UserInit.h"
#include "tlhelp32.h"
#include <winsock2.h> 


CIniFile g_IniFile;
CIniFile g_AccountFile;
CString arrState[] = { L"未完成",L"完成",L"账号错误",L"二密错误",L"武器未装备",L"账号在线",L"Boss已完成" };

map<CString, OcrInfo>ocrMap;

bool bTaskFlag = false;

CString g_TaskName;

CString strTaskName;
CString strMapName;
bool g_TaskState = false;
bool g_sucessState = false;
CString g_Task;
int nXPath = 10;
int rectX = 50;
int SplitVARIANT(CString source, VARIANT* nlist, CString divKey) {

	int j = 0; int Number = 0; int m_pos, d_len = divKey.GetLength();
	while (TRUE)
	{
		m_pos = source.Find(divKey, j);
		if (m_pos == -1 && j == 0) { break; }
		if (m_pos == -1 && j != 0)
		{

			nlist[Number].lVal = _wtof(source.Mid(j, source.GetLength() - j));
			nlist[Number].lVal = nlist[Number].lVal < 0 ? 0 : nlist[Number].lVal;
			break;
		}
		if (j == 0)
		{
			nlist[Number].lVal = _wtof(source.Mid(0, m_pos));
			nlist[Number].lVal = nlist[Number].lVal < 0 ? 0 : nlist[Number].lVal;
		}
		else {
			nlist[Number].lVal = _wtof(source.Mid(j, m_pos - j));
			nlist[Number].lVal = nlist[Number].lVal < 0 ? 0 : nlist[Number].lVal;
		}
		j = m_pos + d_len;
		Number++;
	}
	return Number;
}


CString NumberToString(LONG Number)
{
	CString sTring;
	sTring.Format(_T("%ld"), Number);
	return sTring;
}


DWORD RandomNumber(DWORD dwNumber1, DWORD dwNumber2)
{
	DWORD dwTemp;
	__asm
	{
		push ecx
		push edx
		rdtsc
		mov ecx, 0x17
		mul ecx
		add eax, 0x7
		mov ecx, dwNumber2//ss:[ebp + 0c]
		sub ecx, dwNumber1//ss : [ebp + 8]
		inc ecx
		xor edx, edx
		div ecx
		add edx, dwNumber1//ss : [ebp + 8]
		mov dwTemp, edx
		pop edx
		pop ecx
	}
	return dwTemp;
}
//分割字符串
void StringSplit(CString source, CStringArray& dest, char division)
{
	if (source.IsEmpty())
		return;
	dest.RemoveAll();
	for (int i = 0; i < source.GetLength(); i++)
	{
		if (source.GetAt(i) == division)
		{
			dest.Add(source.Left(i));
			source.Delete(0, i + 1);
			i = 0;
		}
	}
	dest.Add(source);
}

void KillProcess(CString sExeName)
{
	HANDLE hSnapShot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	if (hSnapShot == 0)
		return;
	PROCESSENTRY32 thePE;
	thePE.dwSize = sizeof(PROCESSENTRY32);


	//遍历正在运行的第一个系统进程


	bool Status = Process32First(hSnapShot, &thePE);
	bool bHaveFlag = false;
	DWORD ProcessID = 0;


	while (Status)
	{
		//遍历正在运行的下一个系统进程  
		Status = Process32Next(hSnapShot, &thePE);
		//找到相应的进程 **.exe


		// if(0 == wcscmp(thePE.szExeFile,L""))
		CString sFindName = thePE.szExeFile;
		CString sTemp = sExeName.Mid(0, sFindName.GetLength());


		if (sFindName == sTemp)
		{
			bHaveFlag = true;
			ProcessID = thePE.th32ProcessID;


			////结束指定的进程 ProcessID
			if (!TerminateProcess(OpenProcess(PROCESS_TERMINATE || PROCESS_QUERY_INFORMATION, false, ProcessID), 0))
			{
				//AfxMessageBox(L"无法终止指定的进程！", MB_ICONWARNING || MB_OK);
			}
			else
			{
				//AfxMessageBox(L"进程结束！", MB_ICONWARNING || MB_OK);
				break;
			}
		}
	}
	CloseHandle(hSnapShot);
}

bool runScript( CString sOcrText) {
	//获取ocr数据

	OcrInfo ocrInfo = ocrMap[sOcrText];
	if (ocrInfo.nCount == 0 || ocrInfo.nCount == NULL)
		ocrInfo.nCount = 1;

	bool(*funcOcr[])(OcrInfo) = { CmpCol,FindCol,FindMulCol,FindPic,FindStr,FindColBlock };
	for (int i = 0; i < ocrInfo.nCount; i++)
	{
		if (funcOcr[_wtoi(ocrInfo.sAction)](ocrInfo)) {
			return true;
		}
		
		g_dm->delay(100);
	}
	return false;
}

void(*funcType[])(OcrInfo) = { dmClick,dmDoubleClick };
bool FindMulCol(OcrInfo ocrInfo) { return true; }
bool CmpCol(OcrInfo ocrInfo) { return true; }

void dmClick(OcrInfo ocrInfo) {
	g_dm->LeftClick();
	g_dm->delay(100);
}
void dmDoubleClick(OcrInfo ocrInfo) {
	g_dm->LeftDoubleClick();
	g_dm->delay(100);
}
bool FindCol(OcrInfo ocrInfo) {
	return true;
}
bool FindPic(OcrInfo ocrInfo) {
	VARIANT x, y;
	VARIANT nPoint[4];
	SplitVARIANT(ocrInfo.sPoint, nPoint, L",");
	CString sBmp = ocrInfo.sDescribe != L"" ? ocrInfo.sDescribe : ocrInfo.sName + L".bmp";
	g_dm->FindPic(nPoint[0].lVal - 10, nPoint[1].lVal - 10, nPoint[2].lVal + 10, nPoint[3].lVal + 10, sBmp, L"101010", 0.9f, 0, &x.lVal, &y.lVal);
	if (x.lVal > 0) {
		if (ocrInfo.sType == L"0")
			return true;
		if (ocrInfo.sOffset != L"") {
			VARIANT nOffset[2];
			SplitVARIANT(ocrInfo.sOffset, nOffset, L",");
			ocrInfo.x = nOffset[0].lVal + x.lVal;
			ocrInfo.y = nOffset[1].lVal + y.lVal;
		}
		else {
			ocrInfo.x = x.lVal;
			ocrInfo.y = y.lVal;
		}
		g_dm->MoveTo(ocrInfo.x, ocrInfo.y);
		funcType[_wtoi(ocrInfo.sType) - 1](ocrInfo);
		return true;
	}
	return false;

}
bool FindStr(OcrInfo ocrInfo) { return true; }
bool FindColBlock(OcrInfo ocrInfo) { return true; }
bool runScriptList(CString str) {
	int istart = 0;
	while (istart != -1) {//分割 @符号
		CString m;
		m = str.Tokenize(L"|", istart);
		runScript(m);
		Sleep(100);
	}
	return true;
}

bool moveEX(long nTagX) {
	long nMapX, nMapY, x, y, nX;
	g_dm->KeyUp(37);
	g_dm->KeyUp(39);
	g_dm->FindPic(0, 0, 600, 600, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);
	for (size_t i = 0; i < 10; i++)
	{

		//}
		//while (true)
		//{

		g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 1, 0, &x, &y);
		nX = x - nMapX;
		if (nX - nTagX > 2) {//往左移动
			g_dm->KeyDown(37);
			for (size_t i = 0; i < 200; i++)
			{
				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 1, 0, &x, &y);
				nX = x - nMapX;
				//CString str;
				//str.Format(L"相距坐标%d", abs(nX - nTagX));
				//this->AppendText(str);
				if (abs(nX - nTagX) <= 1 || nX - nTagX < -1) {
					g_dm->KeyUp(37);
					return true;
				}
				Sleep(10);
			}
			g_dm->KeyUp(37);
			//if (abs(nX - nTagX) <= 1 || nX - nTagX < -2) {
			//	break;
			//}



		}
		if (nX - nTagX < -2) {
			g_dm->KeyDown(39);
			for (size_t i = 0; i < 200; i++)
			{
				/*			CString str;
				str.Format(L"相距坐标%d", abs(nX - nTagX));
				this->AppendText(str);*/
				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 1, 0, &x, &y);
				nX = x - nMapX;
				if (abs(nX - nTagX) <= 1 || nX - nTagX > 1) {
					g_dm->KeyUp(39);
					return true;
				}
				Sleep(10);
			}
			g_dm->KeyUp(39);
			//if (abs(nX - nTagX) <= 1 || nX - nTagX > 2) {
			//	break;
			//}
		}

		if (abs(nX - nTagX) <= 1) {
			return true;
		}
	}
	return false;
}

bool MoveToMapEx(CString strPath) {
	CStringArray arr1;
	long x, y;
	StringSplit(strPath, arr1, '|');
	for (size_t i = 0; i < arr1.GetCount(); i++)
	{
		CStringArray arr2;
		StringSplit(arr1.GetAt(i), arr2, ',');

		long nX = _wtoi(arr2.GetAt(0));
		for (size_t j = 0; j < 8; j++)
		{
			if (MoveToMap(nX, arr2.GetAt(1))) {//移动
				CString str;
				str.Format(L"i=%d,map=%s", i, arr2.GetAt(1));
				//AfxMessageBox(str);
				g_dm->KeyUp(37);
				g_dm->KeyUp(39);
				break;
			}
		}
	}
	g_dm->KeyUp(37);
	g_dm->KeyUp(39);
	return true;
}
bool movetoEX(CString strPath) {

	//地图格式 地图坐标X,地图名称,方向|地图坐标  ；方向 0左 1右
	CStringArray arr1;
	long x, y;
	StringSplit(strPath, arr1, '|');
	for (size_t i = 0; i < arr1.GetCount(); i++)
	{
		CStringArray arr2;
		StringSplit(arr1.GetAt(i), arr2, ',');
		
		long nX = _wtoi(arr2.GetAt(0));
		
		for (size_t j = 0; j < 8; j++)
		{

			//查找地图名称是否为移动的名称
			if (movetoX(nX)) {//移动
				for (size_t i = 0; i < 2; i++)
				{
					
					g_dm->KeyPress(38);
					Sleep(50);
				}
				Sleep(5000);
				taskNext();
				CString strMap = g_dm->FindPicS(0, 0, 500, 500, arr2.GetAt(1), L"050505", 0.98, 0, &x, &y);
				if (strMap == arr2.GetAt(1)) {//移动到地图
					g_dm->KeyUp(37);
					g_dm->KeyUp(39);
					break;
				}
				else {//未移动到地图
					//g_dm->KeyPress(38);
					int nKey = 0;
					if (arr2.GetAt(2) == L"0") {//0往左移动 纠正往右  1往右 纠正往左
						nKey = 39;
					}
					else {
						nKey = 37;
					}
					g_dm->KeyDown(nKey);
					Sleep(RandomNumber(1000, 2000));
					g_dm->KeyUp(nKey);
				}
			}
		}
		

	}
	g_dm->KeyUp(37);
	g_dm->KeyUp(39);
	return true;

}

void taskOk() {
	long x, y;
	for (size_t i = 0; i < 5; i++)
	{
		g_dm->FindPic(0, 0, 1280, 960, L"taskOK.bmp", L"101010", 0.9, 0, &x, &y);
		if (x > 0) {
			Sleep(1500);
			g_dm->MoveTo(0, 0);
			g_dm->MoveTo(x, y);
			Sleep(500);
			/*	Sleep(500);*/
			g_dm->LeftClick();
			//Sleep(1500);
			//g_dm->KeyPress(27);
			Sleep(500);
			g_dm->MoveTo(0, 0);
			Sleep(500);
			g_dm->MoveTo(x, y - 300);
			Sleep(1000);
		}
	}
	g_dm->FindPic(0, 0, 1280, 960, L"jieshouTask.bmp", L"101010", 0.9, 0, &x, &y);
	if (x > 0) {//接受不详的预感任务
		Sleep(500);
		g_dm->MoveTo(x+10, y+5);
		Sleep(500);
		g_dm->LeftClick();
		Sleep(500);
		g_dm->MoveTo(x, y + 30);

	}
}
void taskNext() {
	long x, y;
	for (size_t i = 0; i < 10; i++)
	{
		g_dm->FindPic(0, 0, 1024, 700, L"taskOK.bmp", L"101010", 0.9, 0, &x, &y);
		if (x > 0) {
			g_dm->MoveTo(RandomNumber(250, 300), RandomNumber(5, 9));
			Sleep(1500);
			g_dm->MoveTo(x, y);
			g_dm->LeftClick();
			Sleep(1500);
			g_dm->MoveTo(x, y - 100);
		}

		g_dm->FindPic(0, 0, 1024, 700, L"endWnd.bmp|next.bmp|next1.bmp|next2.bmp", L"101010", 0.9, 0, &x, &y);
		if (x > 0) {
			Sleep(300);
			g_dm->KeyPress(32);
			//g_dm->KeyPress(13);
		}
		g_dm->FindPic(0, 0, 1024, 700, L"jieshouTask.bmp|taskQueRen.bmp|task_ZhuanZhi.bmp|yes.bmp", L"101010", 0.9, 0, &x, &y);
		if (x > 0) {//接受任务
			g_dm->MoveTo(RandomNumber(250, 300), RandomNumber(5, 9));
			//g_dm->MoveTo(0, 0);
			Sleep(500);
			g_dm->MoveTo(x + 10, y + 5);
			Sleep(500);
			g_dm->LeftClick();
			Sleep(500);
			g_dm->MoveTo(x, y -30);

		}
	}
	for (size_t i = 0; i < 10; i++)
	{

		CString strShu = g_dm->FindPicS(0, 0, 1024, 800, L"taskDengPao.bmp|taskend.bmp|taskShu.bmp|taskShu1.bmp", L"202020", 0.9, 0, &x, &y);
		if (x > 0) {
			g_dm->MoveTo(RandomNumber(250, 300), RandomNumber(5, 9));
			g_dm->delay(500);
			if (strShu == L"taskShu.bmp" || strShu == L"taskShu1.bmp") {
				g_dm->MoveTo(x - 15, y);
			}
			else {
				g_dm->MoveTo(x + 15, y + 10);
			}
			g_dm->LeftClick();
			g_dm->delay(800);
			g_dm->MoveTo(x + 35, y + 30);
			g_dm->delay(800);
			break;
		}
	}
	//g_dm->FindPic(0, 0, 1280, 960, L"jieshouTask.bmp", L"101010", 0.9, 0, &x, &y);
	//if (x > 0) {//接受不详的预感任务
	//	g_dm->MoveTo(0, 0);
	//	g_dm->MoveTo(x, y);
	//	Sleep(500);
	//	g_dm->LeftClick();
	//	Sleep(500);
	//	g_dm->MoveTo(0, 0);
	//	Sleep(500);
	//	g_dm->MoveTo(x, y -300);

	//}

}


void npcClick(CString strNpc,long x1,long y1) {
	long x, y, x2=0, y2=0;
	for (size_t i = 0; i < 10; i++)
	{
		g_dm->FindPic(0, 0, 1280, 960, strNpc + L".bmp", L"202020", 0.9, 0, &x, &y);
		TRACE(strNpc + NumberToString(x) + L"\r\n");
		if (x > 0) {
			TRACE(strNpc + NumberToString(x) + L"\r\n");
			g_dm->MoveTo(0, 0);
			Sleep(200);
			x2 = x + RandomNumber(1, 3) + x1;
			y2 = y - RandomNumber(28, 35) + y1;
			g_dm->MoveTo(x2, y2);
			Sleep(500);
			g_dm->LeftDoubleClick();
			Sleep(500);
			g_dm->MoveTo(0, 0);
			Sleep(1500);
			g_dm->MoveTo(RandomNumber(500, 600), y + RandomNumber(100, 150));
			Sleep(500);
			break;
		}
		Sleep(10);
	}

}

void closeWndTask() {
	taskOk();
	taskNext();
	long x, y;
	for (size_t i = 0; i < 3; i++)
	{
		g_dm->FindPic(0, 0, 1280, 960, L"endWnd.bmp", L"101010", 0.9, 0, &x, &y);
		if (x > 0) {
			g_dm->KeyPress(27);
			Sleep(1000);
		}
	}

}
void gongji() {
	for (size_t i = 0; i < RandomNumber(3,5); i++)
	{
		g_dm->KeyPress(16);
		Sleep(RandomNumber(10, 30));
	}
}
bool movetoX(long nTagX ,CString &taskName) {

	long nMapX, nMapY, x, y, nX, nPath;
	int j = 0;
	g_dm->KeyUp(37);
	g_dm->KeyUp(39);
	g_dm->FindPic(0, 0, 600, 600, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);
	for (size_t i = 0; i < 10; i++)
	{

		closeWndTask();
		//}
		//while (true)
		//{

		g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
		nX = x - nMapX;
		nPath = nX - nTagX;
		if (nX - nTagX == 0) {
			g_dm->KeyUp(39);
			g_dm->KeyUp(37);
			return true;
		}
		if (nX - nTagX >= 2) {//往左移动
			g_dm->KeyDown(37);
			for (size_t i = 0; i < 200; i++)
			{
				taskName = g_dm->FindPicS(8, 0, 1026, 622, L"task_BuXiangYuGanStart.bmp|moveTo_CaoCong2.bmp|moveTo_CaoCong2_1.bmp", L"101010", 0.9, 0, &x, &y);
				if (x > 0) {
					return true;
				}
				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nX = x - nMapX;
				//CString str;
				//str.Format(L"相距坐标%d", abs(nX - nTagX));
				//this->AppendText(str);
				Sleep(10);
				if (nX - nTagX == 0) {
					//gongji();
					g_dm->KeyUp(37);
					return true;
				}
				if (abs(nX - nTagX) <= 1 || nX - nTagX < -1) {
					//gongji();
					g_dm->KeyUp(37);
					return true;
				}
			}
			g_dm->KeyUp(37);
		}
		if (nX - nTagX <= -2) {
			g_dm->KeyDown(39);
			for (size_t i = 0; i < 200; i++)
			{
				taskName = g_dm->FindPicS(8, 0, 1026, 622, L"task_BuXiangYuGanStart.bmp|moveTo_CaoCong2.bmp|moveTo_CaoCong2_1.bmp", L"050505", 1, 0, &x, &y);
				if (x > 0) {
					return true;
				}
				/*			CString str;
				str.Format(L"相距坐标%d", abs(nX - nTagX));
				this->AppendText(str);*/
				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nX = x - nMapX;
				//Sleep(10);
				if (nX - nTagX == 0) {
					//gongji();
					g_dm->KeyUp(39);
					return true;
				}
				if (abs(nX - nTagX) <= 1 || nX - nTagX > 1) {
					//gongji();
					g_dm->KeyUp(39);
					return true;
				}
				Sleep(10);
			}
			g_dm->KeyUp(39);
			//if (abs(nX - nTagX) <= 1 || nX - nTagX > 2) {
			//	break;
			//}
		}
		if (nPath == nX - nTagX) {
			j++;
		}
		if (j > 3) {
			return false;
		}

	}
	if (abs(nX - nTagX) <= 1) {
		return true;
	}
	return false;
}

bool MoveToMap(long nTagX, CString strMap) {
	long nMapX, nMapY, x, y, nX, nPath;
	int j = 0;
	g_dm->KeyUp(37);
	g_dm->KeyUp(39);
	g_dm->FindPic(0, 0, 600, 600, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);
	for (size_t i = 0; i < 10; i++)
	{
		//如果当前坐标未找到则
		g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
		nX = x - nMapX;
		nPath = nX - nTagX;
		//当前坐标-目的坐标 往左走
		if (nX - nTagX >= 1) {
			g_dm->KeyDown(37);
			for (size_t i = 0; i < 50; i++)
			{
				
				g_dm->FindPic(0, 0, 600, 600, strMap, L"050505", 0.9, 0, &x, &y);
				if (x > 0) {
					g_dm->KeyUp(38);//弹起上键
					g_dm->KeyUp(37);
					return true;
				}
				

				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nX = x - nMapX;
				if (x == -1) {//未找到人物坐标
					g_dm->KeyUp(38);//弹起上键
					g_dm->KeyUp(37);
				}
				if (abs(nX - nTagX) <= 2) {
					g_dm->FindPic(0, 0, 600, 600, strMap, L"050505", 0.9, 0, &x, &y);
					if (x > 0) {
						g_dm->KeyUp(38);//弹起上键
						g_dm->KeyUp(37);
						return true;
					}
					g_dm->KeyPress(38);
					
				}if (abs(nX - nTagX) ==0) {
					g_dm->KeyUp(37);
					g_dm->KeyPress(38);
					g_dm->FindPic(0, 0, 600, 600, strMap, L"050505", 0.9, 0, &x, &y);
					if (x > 0) {
						g_dm->KeyUp(38);//弹起上键
						g_dm->KeyUp(37);
						return true;
					}
				}
				Sleep(50);
			}
		}
		if (nX - nTagX <= -1) {
			g_dm->KeyDown(39);
			for (size_t i = 0; i < 50; i++)
			{
		
				g_dm->FindPic(0, 0, 600, 600, strMap, L"050505", 0.9, 0, &x, &y);
				if (x > 0) {
					g_dm->KeyUp(38);//弹起上键
					g_dm->KeyUp(39);
					return true;
				}
				
				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nX = x - nMapX;

				if (x == -1) {//未找到人物坐标
					g_dm->KeyUp(38);//弹起上键
					g_dm->KeyUp(39);
				}
				if (abs(nX - nTagX) <= 2) {
					g_dm->FindPic(0, 0, 600, 600, strMap, L"050505", 0.9, 0, &x, &y);
					if (x > 0) {
						g_dm->KeyUp(38);//弹起上键
						g_dm->KeyUp(39);
						return true;
					}
					g_dm->KeyPress(38);
					
				}if (abs(nX - nTagX) == 0) {
					g_dm->KeyUp(39);
					g_dm->KeyPress(38);
					g_dm->FindPic(0, 0, 600, 600, strMap, L"050505", 0.9, 0, &x, &y);
					if (x > 0) {
						g_dm->KeyUp(38);//弹起上键
						g_dm->KeyUp(39);
						return true;
					}
				}

				Sleep(50);
			}
		}
		g_dm->KeyUp(37);
		g_dm->KeyUp(39);

	}
}

bool movetoXY(long nTagX) {
	long nMapX, nMapY, x, y, nX,nY, nPath;
	g_dm->FindPic(0, 0, 600, 600, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);
	for (size_t i = 0; i < 10; i++)
	{
		g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
		nX = x - nMapX;
		//Sleep(10);
		if (nX - nTagX == 0) {
			g_dm->KeyUp(39);
			g_dm->KeyUp(37);
			return true;
		}
		if (nX - nTagX > 0) {//当前坐标-目标坐标>0 40 30
			g_dm->KeyDown(37);
			RandomNumber(30, 50);
			g_dm->KeyUp(37);
		}
		if (nX - nTagX < 0) {
			g_dm->KeyDown(39);
			RandomNumber(30, 50);
			g_dm->KeyUp(39);
		}
		Sleep(100);
	}
	return true;
}

bool moveToYEx(long nTagY, CString strMap) {
	long nMapX, nMapY, x, y, nY, nPath, x1, y1;
	int j = 0;
	//CString strMap1;
	g_dm->FindPic(0, 0, 600, 600, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);
	for (size_t i = 0; i < 10; i++)
	{
		taskNext();
		g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
		nY = y - nMapY; //当前坐标Y - 小地图坐标Y = 相对坐标Y

		if (nY - nTagY == 0) {//到达目的地
			g_dm->KeyUp(39);
			g_dm->KeyUp(37);
			return true;
		}
		if (nY - nTagY > 0) {//当前坐标大于 目的坐标往上走 nY=10,nTagY=2
			g_dm->KeyDown(38);

			for (size_t i = 0; i < 200; i++)
			{

				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nY = y - nMapY;

				g_dm->FindPic(0, 0, 470, 150, strMap, L"050505", 1, 0, &x1, &y1);
				if (x1 > 0) {
					g_dm->KeyUp(38);
					g_dm->KeyUp(40);
					return true;
				}
				Sleep(10);
				if (nY - nTagY == 0) {
					g_dm->KeyUp(38);
					g_dm->KeyUp(40);
					return true;
				}
				if (abs(nY - nTagY) <= 2 || nY - nTagY < -1) {
					g_dm->KeyUp(38);
					break;
				}
			}
		}
		if (nY - nTagY < 0) {//当前坐标小于于 目的坐标往下走 nY=10,nTagY=20
			g_dm->KeyDown(40);
			for (size_t i = 0; i < 200; i++)
			{

				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nY = y - nMapY;
				g_dm->FindPic(0, 0, 470, 150, strMap, L"050505", 1, 0, &x1, &y1);
				if (x1 > 0) {
					g_dm->KeyUp(38);
					g_dm->KeyUp(40);
					return true;
				}
				Sleep(10);
				if (nY - nTagY == 0) {
					g_dm->KeyUp(38);
					g_dm->KeyUp(40);
					return true;
				}
				if (abs(nY - nTagY) <= 1) {
					g_dm->KeyUp(40);
					break;
				}
			}
		}
	}
}
bool moveToY(long nTagY) {
	long nMapX, nMapY, x, y, nY, nPath;
	int j = 0;
	g_dm->FindPic(0, 0, 600, 600, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);
	for (size_t i = 0; i < 10; i++)
	{
		taskNext();
		g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
		nY = y - nMapY; //当前坐标Y - 小地图坐标Y = 相对坐标Y
		
		if (nY - nTagY == 0) {//到达目的地
			g_dm->KeyUp(39);
			g_dm->KeyUp(37);
			return true;
		}
		if (nY - nTagY > 0) {//当前坐标大于 目的坐标往上走 nY=10,nTagY=2
			g_dm->KeyDown(38);
			for (size_t i = 0; i < 200; i++)
			{
			
				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nY = y - nMapY;

				Sleep(10);
				if (nY - nTagY == 0) {
					g_dm->KeyUp(38);
					g_dm->KeyUp(40);
					return true;
				}
				if (abs(nY - nTagY) <= 2 || nY - nTagY < -1) {
					g_dm->KeyUp(38);
					break;
				}
			}
		}
		if (nY - nTagY < 0) {//当前坐标小于于 目的坐标往下走 nY=10,nTagY=20
			g_dm->KeyDown(40);
			for (size_t i = 0; i < 200; i++)
			{
				
				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nY = y - nMapY;

				Sleep(10);
				if (nY - nTagY == 0) {
					g_dm->KeyUp(38);
					g_dm->KeyUp(40);
					return true;
				}
				if (abs(nY - nTagY) <= 1) {
					g_dm->KeyUp(40);
					break;
				}
			}
		}
	}
}
bool movetoX1(long nTagX) {

	long nMapX, nMapY, x, y, nX, nPath;
	int j = 0;
	g_dm->KeyUp(37);
	g_dm->KeyUp(39);
	g_dm->FindPic(0, 0, 600, 600, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);
	for (size_t i = 0; i < 10; i++)
	{

		//closeWndTask();
		taskNext();
		//}
		//while (true)
		//{

		g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
		if (x == -1) {
			return false;
		}
		nX = x - nMapX;
		nPath = nX - nTagX;
		if (nX - nTagX == 0) {
			g_dm->KeyUp(39);
			g_dm->KeyUp(37);
			return true;
		}
		if (nX - nTagX >0) {//往左移动
			g_dm->KeyDown(37);
			for (size_t i = 0; i < 200; i++)
			{
				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nX = x - nMapX;
				//CString str;
				//str.Format(L"相距坐标%d", abs(nX - nTagX));
				//this->AppendText(str);
				Sleep(30);
				if (nX - nTagX == 0) {
					g_dm->KeyUp(39);
					g_dm->KeyUp(37);
					break;
				}
				if (abs(nX - nTagX) <= 1 || nX - nTagX < -1) {
					g_dm->KeyUp(39);
					g_dm->KeyUp(37);
					break;
				}
			}
			g_dm->KeyUp(37);
			//if (abs(nX - nTagX) <= 1 || nX - nTagX < -2) {
			//	break;
			//}
		}
		if (nX - nTagX < 0) {
			g_dm->KeyDown(39);
			for (size_t i = 0; i < 200; i++)
			{
				/*			CString str;
				str.Format(L"相距坐标%d", abs(nX - nTagX));
				this->AppendText(str);*/
				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nX = x - nMapX;
				//Sleep(10);
				if (nX - nTagX == 0) {
					g_dm->KeyUp(39);
					g_dm->KeyUp(37);
					break;
				}
				if (abs(nX - nTagX) <= 1 || nX - nTagX > 1) {
					g_dm->KeyUp(37);
					g_dm->KeyUp(39);
					break;
				}
				Sleep(30);
			}
			g_dm->KeyUp(39);
			//if (abs(nX - nTagX) <= 1 || nX - nTagX > 2) {
			//	break;
			//}
		}
	}

	//if (abs(nX - nTagX) <= 1) {
	//	return true;
	//}
	return false;
}

bool movetoX(long nTagX) {

	long nMapX, nMapY, x, y, nX,nPath;
	int j=0;
	g_dm->KeyUp(37);
	g_dm->KeyUp(39);
	g_dm->FindPic(0, 0, 600, 600, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);
	for (size_t i = 0; i < 10; i++)
	{

		//closeWndTask();
		
		//}
		//while (true)
		//{
		g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
		nX = x - nMapX;
		nPath = nX - nTagX;
		if (nX - nTagX == 0) {
			g_dm->KeyUp(39);
			g_dm->KeyUp(37);
			return true;
		}
		taskNext();
		if (nX - nTagX >= 2) {//往左移动
			g_dm->KeyDown(37);
			for (size_t i = 0; i < 200; i++)
			{
				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nX = x - nMapX;
				//CString str;
				//str.Format(L"相距坐标%d", abs(nX - nTagX));
				//this->AppendText(str);
				Sleep(50);
				if (nX - nTagX == 0) {
					g_dm->KeyUp(37);
					return true;
				}
				if (abs(nX - nTagX) <= 1 || nX - nTagX < -1) {
					g_dm->KeyUp(37);
					return true;
				}
				
			}
			g_dm->KeyUp(37);
			//if (abs(nX - nTagX) <= 1 || nX - nTagX < -2) {
			//	break;
			//}
		}
		if (nX - nTagX <= -2) {
			g_dm->KeyDown(39);
			for (size_t i = 0; i < 200; i++)
			{
			
				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nX = x - nMapX;
				//Sleep(10);
				if (nX - nTagX == 0) {
					g_dm->KeyUp(39);
					return true;
				}
				if (abs(nX - nTagX) <= 1 || nX - nTagX > 1) {
					g_dm->KeyUp(39);
					return true;
				}
				Sleep(50);
			}
			g_dm->KeyUp(39);
			//if (abs(nX - nTagX) <= 1 || nX - nTagX > 2) {
			//	break;
			//}
		}
		//if (nPath == nX - nTagX) {
		//	j++;
		//}
		//if (j > 3) {
		//	return false;
		//}
	}
	if (abs(nX - nTagX) <= 1) {
		return true;
	}
	return false;
}

bool moveX(long nTagX) {
	long nMapX, nMapY, x, y, nX, nPath;
	int j = 0;
	g_dm->KeyUp(37);
	g_dm->KeyUp(39);
	g_dm->FindPic(0, 0, 600, 600, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);
	for (size_t i = 0; i < 10; i++)
	{
		g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
		nX = x - nMapX;
		nPath = nX - nTagX;
		if (nX - nTagX == 0) {
			g_dm->KeyUp(39);
			g_dm->KeyUp(37);
			return true;
		}
		if (nX - nTagX >= 2) {//往左移动
			g_dm->KeyDown(37);
			for (size_t i = 0; i < 200; i++)
			{
				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nX = x - nMapX;
				//CString str;
				//str.Format(L"相距坐标%d", abs(nX - nTagX));
				//this->AppendText(str);
				Sleep(50);
				if (nX - nTagX == 0) {
					g_dm->KeyUp(37);
					return true;
				}
				if (abs(nX - nTagX) <= 2|| nX - nTagX < -1) {
					g_dm->KeyUp(37);
					return true;
				}

			}
			g_dm->KeyUp(37);
			//if (abs(nX - nTagX) <= 1 || nX - nTagX < -2) {
			//	break;
			//}
		}
		if (nX - nTagX <= -2) {
			g_dm->KeyDown(39);
			for (size_t i = 0; i < 200; i++)
			{
				/*			CString str;
				str.Format(L"相距坐标%d", abs(nX - nTagX));
				this->AppendText(str);*/
				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				nX = x - nMapX;
				//Sleep(10);
				if (nX - nTagX == 0) {
					g_dm->KeyUp(39);
					return true;
				}
				if (abs(nX - nTagX) <= 2 || nX - nTagX > 1) {
					g_dm->KeyUp(39);
					return true;
				}
				Sleep(50);
			}
			g_dm->KeyUp(39);
			//if (abs(nX - nTagX) <= 1 || nX - nTagX > 2) {
			//	break;
			//}
		}
		if (nPath == nX - nTagX) {
			j++;
		}
		if (j > 3) {
			return false;
		}
	}
	if (abs(nX - nTagX) <= 1) {
		return true;
	}
	return false;
}
void clickNpcAll(CString strNpc) {
}
void JumpGong() {
	JumpGong(false);
}
void JumpGong(bool bJump) {
	long x, y;
	//long rectX = 75;
	int Keyboard = RandomNumber(1, 2) == 1 ? 37 : 39;
	g_dm->KeyDown(Keyboard);
	int nRnd = RandomNumber(6, 10);
	int nRnd1 = RandomNumber(3, 5);
	for (size_t i = 1; i <nRnd; i++)
	{
		g_ckdm->FindPic(0, 0, 1024, 700, L"taskwancheng.bmp", L"101010", 0.95, 0, &x, &y);
		if (x > 0) {
			return;
		}
		//if(nRnd%2)
		if (nRnd1%i == 0 && bJump) {
			g_dm->KeyPress(46);
		}
		buxue(L"pgdn");
		BuLan(L"pgup");
		//CString strTask = g_dm->FindPicS(176, 15, 1024, 311, L"task_BuXiangYuGanEnd.bmp|task_ZhongYaoDongXiEnd.bmp", L"050505", 1, 0, &x, &y);

		////CString strTask = g_dm->FindPicS(176, 15, 1024, 311, L"task_BuXiangYuGan.bmp|task_BuXiangYuGanEnd.bmp|task_ZhongYaoDongXi.bmp|task_HuangJinHaiAn.bmp|task_HuangJinHaiAnEnd.bmp|task_WeiChiZhengJie.bmp|task_WeiChiZhengJieEnd.bmp|task_GuZhangDeYuanYin.bmp|task_GuZhangDeYuanYinEnd.bmp|task_HaiBianYuanZhuMing.bmp|task_HaiBianYuanZhuMingEnd.bmp|task_SiRenHaiTan.bmp|task_SiRenHaiTanEnd.bmp|task_YiShiJieZhi.bmp|task_YiShiJieZhiEnd.bmp|task_HeiSeBoLang.bmp|task_HeiSeBoLangEnd.bmp|task_YiSHiYouYongQuan.bmp|task_YiSHiYouYongQuanEnd.bmp|task_XinXianCaiLiao.bmp|task_XinXianCaiLiaoEnd.bmp|task_DiaoYuWang.bmp|task_DiaoYuWangEnd.bmp|task_BoLangJuanZhou.bmp|task_BoLangJuanZhou.bmp|task_BoLangJuanZhouEnd.bmp|task_HaiXingShuiLing.bmp|task_HaiXingShuiLingEnd.bmp|task_HaiLuoShuiLing.bmp|task_HaiLuoShuiLingEnd.bmp", L"050505", 1, 0, &x, &y);
		//if (strTask != "") {
		//	return;
		//}
		//	
		g_dm->FindPic(0, 0, m_mapArr[2], m_mapArr[3], L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
		if (x > m_mapArr[2] - rectX) {
			Keyboard = mapKey[L"left"];
			g_dm->KeyUp(mapKey[L"right"]);
			Sleep(RandomNumber(100, 200));
			g_dm->KeyDown(Keyboard);
		}
		if (x < m_mapArr[0] + rectX) {
			Keyboard = mapKey[L"right"];
			g_dm->KeyUp(mapKey[L"left"]);
			Sleep(RandomNumber(100, 200));
			g_dm->KeyDown(Keyboard);
		}
		Sleep(RandomNumber(200, 500));
		g_dm->KeyDown(18);
		Sleep(RandomNumber(80, 130));
		g_dm->KeyUp(18);
		Sleep(RandomNumber(120, 250));
		g_dm->KeyDown(18);
		Sleep(RandomNumber(70, 110));
		g_dm->KeyUp(18);
		Sleep(RandomNumber(60, 150));
		for (size_t i = 0; i < 4; i++)
		{
			g_dm->KeyDown(16);
			Sleep(RandomNumber(70, 110));
			g_dm->KeyUp(16);
			Sleep(RandomNumber(200, 500));
		}
	}
	


}

unsigned WINAPI CheckTaskJinHaiAn(PVOID pParam) {
	long x,y,nMapX, nMapY,nX, nPath;
	//long nX, nY;
	g_dm->FindPic(0, 0, 200, 200, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);
	int i = 0;
	while (bTaskFlag)
	{
		g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);

		nX = x - nMapX;
		Sleep(1000);
		g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
		nPath = x - nMapX;
		if (nX == nPath) {
			i++;
		}
		g_dm->FindPic(0, 0, 200, 200, L"gameTag.bmp", L"050505", 0.9, 0, &x, &y);
		if (x > 0) {
			Sleep(500);
			g_dm->MoveTo(RandomNumber(50, 80), RandomNumber(5, 9));
			Sleep(500);
			g_dm->MoveTo(RandomNumber(850, 1000), RandomNumber(700, 710));
			Sleep(500);
			g_dm->LeftDoubleClick();
			Sleep(500);
		}
		
		if (i > 10) {
			g_dm->MoveTo(RandomNumber(50, 80), RandomNumber(5, 9));
			Sleep(1000);
			g_dm->MoveTo(RandomNumber(850, 1000), RandomNumber(700,710));
			Sleep(1000);
			g_dm->LeftDoubleClick();
			Sleep(1000);
			i = 0;
			//int a = 0;
		}
		//nPath = nX - nTagX;
	}
	return 0;
}

unsigned WINAPI TaskLieNaHaiXia(PVOID pParam) {
	long x, y;
	long hwnd = _wtol(g_dm->EnumWindow(0, L"MKSWindow#0", L"MKSEmbedded", 1 + 2));
	int ret = g_dm->BindWindowEx(hwnd, L"normal", L"normal", L"normal", L"", 0);
	Sleep(2000);
	g_dm->SetWindowState(hwnd, 12);

	Sleep(2000);

	long nMapX, nMapY,nY;
	//long nX, nY;
	g_dm->FindPic(0, 0, 200, 200, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);

	g_dm->FindPic(0, 0, 500, 380, L"minMapLeft.bmp", L"202020", 0.9, 0, &x, &y);
	m_mapArr[0] = x;
	m_mapArr[1] = 80;

	g_dm->FindPic(0, 0, 600, 400, L"minMap.bmp", L"000000", 0.98, 0, &x, &y);
	m_mapArr[2] = x + 15;
	m_mapArr[3] = y + 50;

	bool stateTask = false,bCheck=false,bPath=false;
	CString strZhiXian, strPath, strTag,strMaps;
	CString MoveTo;
	int i = 0, k = 0,j=0;
	int taskPath = 1;
	//g_dm->delay(1000);
	g_dm->MoveTo(983,722);
	g_dm->LeftDoubleClick();
	strMaps = L"map_RuiEnCun.bmp|map_QiErGangKou.bmp|map_GuanCeZongBu.bmp|map_HaiYangZhongYang.bmp|map_DiYiGuanCe.bmp|map_DiYiGuanCe1_1.bmp|map_DiYiGuanCe1_2.bmp|map_DiYiGuanCe1_3.bmp|map_MiLu.bmp|map_DiErGuanCeZhan.bmp|map_DiErGuanCeZhan1_1.bmp|map_DiErGuanCeZhan1_2.bmp|map_DiErGuanCeZhan1_3.bmp|map_BaBaLa.bmp|map_DiSanGuanCe.bmp|map_DiSanGuanCe1_1.bmp|map_DiSanGuanCe1_2.bmp|map_DiSanGuanCe1_3.bmp|map_FanRenJiDi.bmp|map_FanRenJiDi1_1.bmp|map_FanRenJiDi1_2.bmp|map_BinHeBoss.bmp";
	rectX = 75;
	while (bTaskFlag)
	{


		//g_dm->MoveTo(0,0);
		g_dm->FindPic(0, 0, 1024, 600, L"ZhanTing.bmp", L"050505", 1, 0, &x, &y);
		if (x > 0) {
			Sleep(5000);
		}

		CString strMap = g_dm->FindPicS(0, 0, 470, 150, strMaps, L"050505", 1, 0, &x, &y);
		
		
		CString strTask = g_dm->FindPicS(133, 17, 1003, 482, L"task_QianWangHaiXia.bmp|task_HangHaiXianChang.bmp|task_HangHaiXianChangEnd.bmp|task_DiYiGuanCe.bmp|task_JiTuiHuaShi1.bmp|task_JiTuiHuaShi1End.bmp|task_JiTuiHuaShi2.bmp|task_JiTuiHuaShi2End.bmp|task_JieJiuXueZhe.bmp|task_HuiGuanCeZongBu.bmp|task_DiErGuanCeSuo.bmp|task_DiErGuanCeSuo.bmp|task_JingRenErChou.bmp|task_JingRenErChou1End.bmp|task_JingRenErChou2.bmp|task_JingRenErChou2End.bmp|task_QianWangMoNv.bmp|task_QianWangMoNv1.bmp|task_DiaoYu.bmp|task_DiaoYuEnd.bmp|task_HuiGuanCeZongBu1.bmp|task_DiSanGuanCeSuo.bmp|task_GuiYiHaiBao.bmp|task_GuiYiHaiBaoEnd.bmp|task_GuiYiHaiBao1.bmp|task_GuiYiHaiBao1End.bmp|task_GuiYiZhengJu.bmp|task_GuiYiZhengJuEnd.bmp|task_HuiGuanCeZongBu2.bmp|task_FanRenJiDI.bmp|task_BinHeFanRen.bmp|task_BinHeFanRen.bmp|task_BinHeFanRenEnd.bmp|task_BinHeFanRen2.bmp|task_BinHeFanRen2End.bmp|task_BinHeBoss.bmp|task_BinHeBossEnd.bmp|task_HuiGuanCeZongBu3.bmp", L"050505", 1, 0, &x, &y);



		taskNext();

		
		//回观测总部 
		if (strTask == L"task_HuiGuanCeZongBu.bmp"  || strTask == L"task_QianWangMoNv.bmp" || strTask ==L"task_HuiGuanCeZongBu1.bmp" || strTask == L"task_HuiGuanCeZongBu2.bmp" || strTask == L"task_HuiGuanCeZongBu3.bmp") {
			//打开背包
			//定位物品栏
			//传送回城
			for (size_t i = 0; i < 5; i++)
			{
				g_dm->FindPic(0, 0, 800, 600, L"map_GuanCeZongBu.bmp", L"050505", 1, 0, &x, &y);
				if (x > 0) {
					break;
				}
				g_dm->FindPic(0, 0, 800, 600, L"bagWnd.bmp", L"050505", 0.9, 0, &x, &y);
				if (x > 0) {//存在
					Sleep(500);

					long x1, y1;
					g_dm->FindPic(0, 0, 800, 600, L"wupinsuoxiao.bmp", L"050505", 0.9, 0, &x1, &y1);
					if (x1 > 0) {
						Sleep(500);
						g_dm->MoveTo(5, 5);
						Sleep(500);
						g_dm->MoveTo(x1 + RandomNumber(3, 8), y1 + RandomNumber(3, 8));
						Sleep(1000);
						g_dm->LeftClick();
						Sleep(1500);
					}
					g_dm->FindPic(0, 0, 800, 600, L"bagWnd.bmp", L"050505", 0.9, 0, &x, &y);
					g_dm->FindPic(0, 0, 800, 600, L"wupinWnd.bmp", L"050505", 0.9, 0, &x1, &y1);
					if (x1 == -1) {
						g_dm->MoveTo(5, 5);
						Sleep(500);
						g_dm->MoveTo(x - RandomNumber(15, 20), y + 30);
						Sleep(1000);
						g_dm->LeftClick();
					}


					Sleep(2000);
					g_dm->FindPic(0, 0, 1024, 700, L"HuiCheng.bmp", L"050505", 0.9, 0, &x, &y);
					if (x > 0) {
						g_dm->MoveTo(5, 5);
						Sleep(500);
						g_dm->MoveTo(x + RandomNumber(5, 15), y + RandomNumber(10, 15));
						Sleep(1000);
						g_dm->LeftDoubleClick();
						Sleep(4000);
						g_dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"050505", 1, 0, &x, &y);
						if (x > 0) {
							g_dm->KeyPress(73);//关闭背包
							Sleep(2000);
							continue;
						}
					}
				}
				else {//不存在
					Sleep(500);
					g_dm->KeyPress(73);
					Sleep(500);
				}
			}

		}

		//task_QianWangHaiXia
		if (strMap == L"map_RuiEnCun.bmp") {//瑞恩村
			bCheck = true;
			taskPath = 150;
			if (strTask == L"task_QianWangHaiXia.bmp") {
				//task_YiDong
				g_dm->FindPic(0, 0, 670, 350, L"task_YiDong.bmp", L"050505", 1, 0, &x, &y);
				if (x > 0) {
					g_dm->MoveTo(RandomNumber(150, 270), RandomNumber(5, 9));
					g_dm->delay(1000);
					g_dm->MoveTo(x + 15, y + 10);
					g_dm->LeftClick();
					g_dm->delay(800);
					g_dm->MoveTo(RandomNumber(150, 270), RandomNumber(5, 9));
					g_dm->delay(1800);
				}
				//task_YiDong
				g_dm->FindPic(0, 0, 670, 650, L"task_KuaiSu.bmp", L"050505", 1, 0, &x, &y);
				if (x > 0) {
					g_dm->MoveTo(RandomNumber(150, 270), RandomNumber(5, 9));
					g_dm->delay(1000);
					g_dm->MoveTo(x - 100, y + 70);
					g_dm->LeftClick();
					g_dm->delay(800);
					g_dm->MoveTo(RandomNumber(150, 270), RandomNumber(5, 9));
					g_dm->delay(1800);
					taskPath = 80;
				}
				
			}
		}

		if (strMap == L"map_QiErGangKou.bmp") {
			taskPath = 80;
			g_dm->FindPic(0, 0, 870, 850, L"npc_QiE.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				g_dm->MoveTo(RandomNumber(150, 270), RandomNumber(5, 9));
				g_dm->delay(1000);
				g_dm->MoveTo(x + 15, y -20);
				g_dm->LeftClick();
				g_dm->delay(800);
				g_dm->MoveTo(RandomNumber(150, 270), RandomNumber(5, 9));
				g_dm->delay(1800);
			}
		}

		if (strMap == L"map_GuanCeZongBu.bmp") {//冰河观测总部
			taskPath = 115;
			g_dm->FindPic(0, 0, 800, 600, L"miniNpcTag.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				if (x - nMapX >= 159) {
					taskPath = 140;
					bPath = true;
				}
			}
			g_dm->FindPic(0, 0, 800, 600, L"miniNpcTag1.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				//taskPath = 140;
				//bPath = true;
				////x53 y78 x155 y71
				//strPath = L"146,map_HaiYangZhongYang.bmp,1";
				//if (movetoEX(strPath)) {
				//	if (movetoX(53)) {
				//		if (moveToY(75)) {
				//			if (movetoX(140)) {
				//				if (moveToY(71)) {
				//				//if(moveToYEx(70, L"map_FanRenJiDi.bmp")){
				//					strPath = L"155,map_FanRenJiDi.bmp,1";
				//					if (movetoEX(strPath)) {
				//						taskPath = 50;
				//					}
				//				}
				//			}
				//		}
				//	}
				//}
			}
			if (bPath) {
				taskPath = 140;
			}
			if (strTask == L"task_FanRenJiDI.bmp") {
				strPath = L"146,map_HaiYangZhongYang.bmp,1";
				if (movetoEX(strPath)) {
					if (movetoX1(53)) {
						if (moveToY(75)) {
							if (movetoX1(140)) {
								//if (moveToYEx(70, L"map_FanRenJiDi.bmp")) {
									if (moveToY(71)) {
									strPath = L"155,map_FanRenJiDi.bmp,1";
									if (movetoEX(strPath)) {
										taskPath = 50;
									}
								}
							}
						}
					}
				}
			}
			g_dm->FindPic(0, 0, 800, 600, L"bagWnd.bmp", L"050505", 0.9, 0, &x, &y);
			if (x > 0) {
				Sleep(500);
				g_dm->KeyPress(73);
				Sleep(500);
			}
			
			bCheck = true;
			if (strTask == L"task_HangHaiXianChang.bmp"|| strTask == L"task_DiYiGuanCe.bmp") {
				////if (movetoX1(146)) {
				//	Sleep(1000);
				//	g_dm->KeyPress(38);
				//	Sleep(300);
				//	for (size_t i = 0; i < 5; i++)
				//	{

				//		g_dm->MoveTo(RandomNumber(250, 300), RandomNumber(5, 9));
				//		taskNext();
				//		Sleep(1500);
				//		strMap = g_dm->FindPicS(0, 0, 470, 150, L"map_RuiEnCun.bmp|map_GuanCeZongBu.bmp|map_HaiYangZhongYang.bmp", L"050505", 1, 0, &x, &y);
				//		if (strMap == L"map_HaiYangZhongYang.bmp") {
				//			break;
				//		}
				//	}
					

				//}

				strPath = L"146,map_HaiYangZhongYang.bmp,1";
				if (movetoEX(strPath)) {
					Sleep(1000);
					taskNext();
					Sleep(1000);
					strMap = g_dm->FindPicS(0, 0, 470, 150, strMaps, L"050505", 1, 0, &x, &y);
					taskPath = 0;
					bCheck = true;
				}
			}

			//"坐标,地图名称，方向
			if (strTask == L"task_DiErGuanCeSuo.bmp") {
				taskPath = 0;
				strPath = L"146,map_HaiYangZhongYang.bmp,1";
				if (movetoEX(strPath)) {
					if (moveToY(104)) {//if (moveToYEx(105, L"map_HaiYangZhongYang.bmp")) {
						if (movetoX1(40)) {
							Sleep(2000);
							//strPath = L"56,map_DiErGuanCeZhan.bmp,1";
							if (moveToY(118)) {//if (moveToYEx(118, L"map_HaiYangZhongYang.bmp")) {
								strPath = L"56,map_DiErGuanCeZhan.bmp,0";
								if (movetoEX(strPath)) {

								}
							}


						}
					}
				}

				// 30,105,40,105,40,119,57,118

				/*if (movetoX1(146)) {
					Sleep(1000);
					g_dm->KeyPress(38);
					Sleep(300);
					for (size_t i = 0; i < 5; i++)
					{

						g_dm->MoveTo(RandomNumber(250, 300), RandomNumber(5, 9));
						taskNext();
						Sleep(1500);
						strMap = g_dm->FindPicS(0, 0, 470, 150, L"map_RuiEnCun.bmp|map_GuanCeZongBu.bmp|map_HaiYangZhongYang.bmp", L"050505", 1, 0, &x, &y);
						if (strMap == L"map_HaiYangZhongYang.bmp") {
							break;
						}
					}


				}*/
			}
			if (strTask == L"task_QianWangMoNv1.bmp") {
				strPath = L"146,map_HaiYangZhongYang.bmp,1";
				if (movetoEX(strPath)) {
					if (moveToY(103)) {
						if (movetoX1(48)) {
							//strPath = L"56,map_DiErGuanCeZhan.bmp,1";
							if (moveToY(130)) {
								strPath = L"158,map_BaBaLa.bmp,0";
								if (movetoEX(strPath)) {
									taskPath = 80;
								}
							}


						}
					}
				}
			}

			if (strTask == L"task_DiSanGuanCeSuo.bmp") {
				//115 74
				strPath = L"146,map_HaiYangZhongYang.bmp,1";
				if (movetoEX(strPath)) {
					if (movetoX1(115)) {
						if (moveToYEx(74, L"map_DiSanGuanCe.bmp"))
						{
							taskPath = 80;
						}
					}
				}
			}

			
			//53,78,155,78
		}

		if (strMap == L"map_HaiYangZhongYang.bmp") {//海洋中央
			taskPath = 0;//不执行移动
			if (strTask == L"task_HangHaiXianChang.bmp") {
				Sleep(200);
				taskNext();
				if (movetoX1(35)) {
					if (moveToY(98)) {
					}
				}
			}

			if (strTask == L"task_HangHaiXianChangEnd.bmp") {
				if (moveToY(92)) {
					strPath = L"30,map_GuanCeZongBu.bmp,0";
					if (movetoEX(strPath)) {
						taskPath = 80;
					}
				}

				//if (moveToYEx(92, L"map_GuanCeZongBu.bmp")) {
				//	taskPath = 80;
				//	//for (size_t i = 0; i < 5; i++)
				//	//{
				//	//	taskNext();
				//	//	Sleep(1500);
				//	//	strMap = g_dm->FindPicS(0, 0, 470, 150, L"map_DiYiGuanCe.bmp", L"050505", 1, 0, &x, &y);
				//	//	if (strMap == L"map_DiYiGuanCe.bmp") {
				//	//		movetoX1(115);
				//	//		break;
				//	//	}
				//	//}
				//}
			}

			if (strTask == L"task_DiYiGuanCe.bmp") {//第一观测移动
				//54,70
				Sleep(2000);
				taskNext();
				Sleep(3000);
				taskNext();
				if (movetoX1(45)) {//if (movetoX1(54)) {
					//movetoXY(54);
					if (moveToY(68)) {//if (moveToYEx(67, L"map_DiYiGuanCe.bmp")) {
						Sleep(1000);
						strPath = L"54,map_DiYiGuanCe.bmp,1";
						if (movetoEX(strPath)) {
						}
						//for (size_t i = 0; i < 5; i++)
						//{
						//	taskNext();
						//	Sleep(1500);
						//	g_dm->FindPic(0, 0, 470, 150, L"map_DiYiGuanCe.bmp", L"050505", 1, 0, &x, &y);
						//	if (x>0) {
						//		movetoX1(80);
						//		break;
						//	}
						//}
					}
				}
			}


			if (strTask == L"task_DiaoYuEnd.bmp") {
				
				if (movetoX1(123)) {
					Sleep(2000);
					if (moveToY(132)) {
						strPath = L"158,map_BaBaLa.bmp,0";
						if (movetoEX(strPath)) {
							taskPath = 80;
						}
					}
				}
			}//钓鱼结束


		}

		if (strMap == L"map_DiYiGuanCe.bmp") {//第一观测任务
			bCheck = true;
			taskPath = 80;
			if (strTask == L"task_JiTuiHuaShi1.bmp") {
				strPath = L"117,map_DiYiGuanCe1_1.bmp,1";
				if (movetoEX(strPath)) {
					stateTask = true;
				}
				//117
			}//29
			if (strTask == L"task_JiTuiHuaShi2.bmp") {
				strPath = L"117,map_DiYiGuanCe1_1.bmp,1|117,map_DiYiGuanCe1_2.bmp,1|112,map_DiYiGuanCe1_3.bmp,1";
				if (movetoEX(strPath)) {
					stateTask = true;
				}
			}
			if (strTask == L"task_JieJiuXueZhe.bmp") {
				strPath = L"52,map_HaiYangZhongYang.bmp,0|27,map_MiLu.bmp,1";
				if (movetoEX(strPath)) {
					taskNext();
					taskPath = 32;
					//if (movetoX1(27)) {
					//	for (size_t i = 0; i < 5; i++)
					//	{
					//		g_dm->KeyPress(38);
					//		Sleep(4000);
					//		g_dm->FindPicS(0, 0, 470, 150, L"map_MiLu.bmp", L"050505", 1, 0, &x, &y);
					//		if (x > 0) {
					//			break;
					//		}
					//	}
					//}
				}
				//strPath = L"117,map_DiYiGuanCe1_1.bmp,1|117,map_DiYiGuanCe1_2.bmp,1|112,map_DiYiGuanCe1_3.bmp,1";
				//if (movetoEX(strPath)) {
				//	stateTask = true;
				//}
			}
#pragma region 旧回观测总部
			//if (strTask == L"task_HuiGuanCeZongBu.bmp") {
			//	//打开背包
			//	//定位物品栏
			//	//传送回城
			//	for (size_t i = 0; i < 5; i++)
			//	{
			//		g_dm->FindPic(0, 0, 800, 600, L"map_GuanCeZongBu.bmp", L"050505", 1, 0, &x, &y);
			//		if (x > 0) {
			//			break;
			//		}
			//		g_dm->FindPic(0, 0, 800, 600, L"bagWnd.bmp", L"050505", 0.9, 0, &x, &y);
			//		if (x > 0) {//存在
			//			Sleep(500);

			//			long x1, y1;
			//			g_dm->FindPic(0, 0, 800, 600, L"wupinsuoxiao.bmp", L"050505", 0.9, 0, &x1, &y1);
			//			if (x1 > 0) {
			//				Sleep(500);
			//				g_dm->MoveTo(5, 5);
			//				Sleep(500);
			//				g_dm->MoveTo(x1 + RandomNumber(3, 8), y1 + RandomNumber(3, 8));
			//				Sleep(1000);
			//				g_dm->LeftClick();
			//				Sleep(1500);
			//			}
			//			g_dm->FindPic(0, 0, 800, 600, L"bagWnd.bmp", L"050505", 0.9, 0, &x, &y);
			//			g_dm->FindPic(0, 0, 800, 600, L"wupinWnd.bmp", L"050505", 0.9, 0, &x1, &y1);
			//			if (x1 == -1) {
			//				g_dm->MoveTo(5, 5);
			//				Sleep(500);
			//				g_dm->MoveTo(x - RandomNumber(15, 20), y + 30);
			//				Sleep(1000);
			//				g_dm->LeftClick();
			//			}


			//			Sleep(2000);
			//			g_dm->FindPic(0, 0, 1024, 700, L"HuiCheng.bmp", L"050505", 0.9, 0, &x, &y);
			//			if (x > 0) {
			//				g_dm->MoveTo(5, 5);
			//				Sleep(500);
			//				g_dm->MoveTo(x + RandomNumber(5, 15), y + RandomNumber(10, 15));
			//				Sleep(1000);
			//				g_dm->LeftDoubleClick();
			//				Sleep(4000);
			//				g_dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"050505", 1, 0, &x, &y);
			//				if (x > 0) {
			//					g_dm->KeyPress(73);//关闭背包
			//					Sleep(2000);
			//					continue;
			//				}
			//			}
			//		}
			//		else {//不存在
			//			Sleep(500);
			//			g_dm->KeyPress(73);
			//			Sleep(500);
			//		}
			//	}

			//}
#pragma endregion

			
			
		}

		if (strMap == L"map_DiYiGuanCe1_1.bmp") {
			if (strTask == L"task_JiTuiHuaShi1End.bmp") {
				strPath = L"28,map_DiYiGuanCe.bmp,0";
				if (movetoEX(strPath)) {
					taskPath = 80;
					stateTask = false;
				}
			}
		}

		if (strMap == L"map_DiYiGuanCe1_3.bmp") {
			if (strTask == L"task_JiTuiHuaShi2End.bmp") {
				strPath = L"29,map_DiYiGuanCe1_2.bmp,1|27,map_DiYiGuanCe1_1.bmp,1|27,map_DiYiGuanCe.bmp,1";
				if (movetoEX(strPath)) {
					stateTask = false;
				}
			}
		}

		if (strMap == L"map_MiLu.bmp") {
			taskPath = 80;
			if (j < 2) {
				//stateTask = true;
				moveGong();
			}
			else {
				//stateTask = false;
			}
			j++;
			g_dm->FindPic(0, 0, 1000, 350, L"npc_NuoLa.bmp", L"050505", 1, 0, &x, &y);
			if (x>0) {
				g_dm->MoveTo(RandomNumber(150, 270), RandomNumber(5, 9));
				g_dm->delay(1000);
				g_dm->MoveTo(x + 30, y - 50);
				g_dm->LeftClick();
				taskNext();
				g_dm->delay(800);
				taskNext();
				g_dm->MoveTo(RandomNumber(150, 270), RandomNumber(5, 9));
				g_dm->delay(1800);
				taskNext();
			}

			//
		}

		if (strMap == L"map_DiErGuanCeZhan.bmp")//第二观测站
		{
			bCheck = true;
			taskPath = 80;
			if (strTask == L"task_JingRenErChou.bmp") {
				strPath = L"115,map_DiErGuanCeZhan1_1.bmp,1";
				if (movetoEX(strPath)) {
					stateTask = true;
				}
				//117
			}
			if (strTask == L"task_JingRenErChou2.bmp") {
				strPath = L"115,map_DiErGuanCeZhan1_1.bmp,1|122,map_DiErGuanCeZhan1_2.bmp,1|122,map_DiErGuanCeZhan1_3.bmp,1";
				if (movetoEX(strPath)) {
					stateTask = true;
				}
				//117
			}
#pragma region 旧版回城
			//if (strTask == L"task_QianWangMoNv.bmp") {
			//	//52  -- 55,133
			//	for (size_t i = 0; i < 5; i++)
			//	{
			//		g_dm->FindPic(0, 0, 800, 600, L"map_GuanCeZongBu.bmp", L"050505", 1, 0, &x, &y);
			//		if (x > 0) {
			//			break;
			//		}
			//		g_dm->FindPic(0, 0, 800, 600, L"bagWnd.bmp", L"050505", 0.9, 0, &x, &y);
			//		if (x > 0) {//存在
			//			Sleep(500);

			//			long x1, y1;
			//			g_dm->FindPic(0, 0, 800, 600, L"wupinsuoxiao.bmp", L"050505", 0.9, 0, &x1, &y1);
			//			if (x1 > 0) {
			//				Sleep(500);
			//				g_dm->MoveTo(5, 5);
			//				Sleep(500);
			//				g_dm->MoveTo(x1 + RandomNumber(3, 8), y1 + RandomNumber(3, 8));
			//				Sleep(1000);
			//				g_dm->LeftClick();
			//				Sleep(1500);
			//			}
			//			g_dm->FindPic(0, 0, 800, 600, L"bagWnd.bmp", L"050505", 0.9, 0, &x, &y);
			//			g_dm->FindPic(0, 0, 800, 600, L"wupinWnd.bmp", L"050505", 0.9, 0, &x1, &y1);
			//			if (x1 == -1) {
			//				g_dm->MoveTo(5, 5);
			//				Sleep(500);
			//				g_dm->MoveTo(x - RandomNumber(15, 20), y + 30);
			//				Sleep(1000);
			//				g_dm->LeftClick();
			//			}


			//			Sleep(2000);
			//			g_dm->FindPic(0, 0, 1024, 700, L"HuiCheng.bmp", L"050505", 0.9, 0, &x, &y);
			//			if (x > 0) {
			//				g_dm->MoveTo(5, 5);
			//				Sleep(500);
			//				g_dm->MoveTo(x + RandomNumber(5, 15), y + RandomNumber(10, 15));
			//				Sleep(1000);
			//				g_dm->LeftDoubleClick();
			//				Sleep(4000);
			//				g_dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"050505", 1, 0, &x, &y);
			//				if (x > 0) {
			//					g_dm->KeyPress(73);//关闭背包
			//					Sleep(2000);
			//					continue;
			//				}
			//			}
			//		}
			//		else {//不存在
			//			Sleep(500);
			//			g_dm->KeyPress(73);
			//			Sleep(500);
			//		}
			//	}
			//}
#pragma endregion


		}

		if (strMap == L"map_DiErGuanCeZhan1_1.bmp") {
			taskPath = 50;
			if (strTask == L"task_JingRenErChou1End.bmp") {
				strPath = L"18,map_DiErGuanCeZhan.bmp,0";
				if (movetoEX(strPath)) {
					taskPath = 80;
					stateTask = false;
				}
			}
		}

		if (strMap == L"map_DiErGuanCeZhan1_3.bmp") {
			
			if (strTask == L"task_JingRenErChou2End.bmp") {
				strPath = L"27,map_DiErGuanCeZhan1_2.bmp,1|18,map_DiErGuanCeZhan1_1.bmp,1|18,map_DiErGuanCeZhan.bmp,1";
				if (movetoEX(strPath)) {
					taskPath = 80;
					stateTask = false;
				}
			}
		}

		if (strMap == L"map_BaBaLa.bmp") {
			bCheck = true;
			taskPath = 80;
			if (strTask == L"task_DiaoYu.bmp") {
				//x43,x121,y111,x188
				strPath = L"43,map_HaiYangZhongYang.bmp,0|121,map_HaiYangZhongYang.bmp,0";
				if (movetoEX(strPath)) {
					if (moveToY(111)) {
						if (movetoX(188)) {
							for (size_t i = 0; i < 20; i++)
							{
								//打开背包
								//点击鱼饵
								g_dm->FindPic(0, 0, 800, 600, L"bagWnd.bmp", L"050505", 0.9, 0, &x, &y);
								if (x > 0) {//存在
									taskNext();
									long x1, y1;
									Sleep(1000);
									g_dm->FindPic(0, 0, 800, 600, L"wupinsuoxiao.bmp", L"050505", 0.9, 0, &x1, &y1);
									if (x1 > 0) {
										Sleep(500);
										g_dm->MoveTo(5, 5);
										Sleep(500);
										g_dm->MoveTo(x1 + RandomNumber(3, 8), y1 + RandomNumber(3, 8));
										Sleep(1000);
										g_dm->LeftClick();
										Sleep(1500);
									}
									g_dm->FindPic(0, 0, 800, 600, L"bagWnd.bmp", L"050505", 0.9, 0, &x, &y);
									g_dm->FindPic(0, 0, 800, 600, L"wupinWnd.bmp", L"050505", 0.9, 0, &x1, &y1);
									if (x1 == -1) {
										g_dm->MoveTo(5, 5);
										Sleep(500);
										g_dm->MoveTo(x - RandomNumber(15, 20), y + 30);
										Sleep(1000);
										g_dm->LeftClick();
									}

									Sleep(2000);
									g_dm->FindPic(0, 0, 1024, 700, L"task_YuEr.bmp", L"050505", 0.9, 0, &x, &y);
									if (x > 0) {
										g_dm->MoveTo(5, 5);
										Sleep(500);
										g_dm->MoveTo(x + RandomNumber(5, 15), y + RandomNumber(10, 15));
										Sleep(1000);
										g_dm->LeftDoubleClick();
										Sleep(1000);
										g_dm->MoveTo(x + RandomNumber(15, 20), y + 30);
										Sleep(1000);
									}
									g_dm->FindPic(0, 0, 800, 600, L"task_DiaoYuEnd.bmp", L"050505", 0.9, 0, &x1, &y1);
									if (x1 > 0) {
										break;
									}

								}
								else {
									Sleep(500);
									g_dm->KeyPress(73);
									Sleep(500);
								}
							}

						}
					}
				}
			}
			
		}

		if (strMap == L"map_DiSanGuanCe.bmp") {//第三观测所
			taskPath = 90;
			if (strTask == L"task_GuiYiHaiBao.bmp" || strTask == L"task_GuiYiHaiBao1.bmp") {
				strPath = L"135,map_DiSanGuanCe1_1.bmp,0";
				if (movetoEX(strPath)) {
					stateTask = true;
				}
			}
			if (strTask == L"task_GuiYiZhengJu.bmp") {
				strPath = L"135,map_DiSanGuanCe1_1.bmp,0|138,map_DiSanGuanCe1_2.bmp,0|136,map_DiSanGuanCe1_3.bmp,0";
				if (movetoEX(strPath)) {
					stateTask = true;
				}
			}
			
			
		}

		if (strMap == L"map_DiSanGuanCe1_1.bmp") {
			taskPath = 90;
			if (strTask == L"task_GuiYiHaiBaoEnd.bmp" || strTask == L"task_GuiYiHaiBao1End.bmp") {
				strPath = L"18,map_DiSanGuanCe.bmp,0|90,map_DiSanGuanCe.bmp,0";
				if (movetoEX(strPath)) {
					for (size_t i = 0; i < 5; i++)
					{
						taskPath = 90;
						g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
						long nY = y - nMapY;
						if (nY > 87) {
							g_dm->KeyPress(35);
							Sleep(1000);
						}
					}
					stateTask = false;
				}
			}
		}

		if (strMap == L"map_DiSanGuanCe1_3.bmp") {
			taskPath = 80;
			if (strTask == L"task_GuiYiZhengJuEnd.bmp") {
				strPath = L"19,map_DiSanGuanCe1_2.bmp,0|19,map_DiSanGuanCe1_1.bmp,0|19,map_DiSanGuanCe.bmp,0|90,map_DiSanGuanCe.bmp,0";
				if (movetoEX(strPath)) {
					for (size_t i = 0; i < 5; i++)
					{
						g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
						long nY = y - nMapY;
						if (nY > 87) {
							g_dm->KeyPress(35);
							Sleep(1000);
						}
					}
					stateTask = false;
				}
			}
		}
		
		if (strMap == L"map_BinHeBoss.bmp") {
			taskPath = 50;
			//16task_BinHeBossEnd
			if (strTask == L"task_BinHeBossEnd.bmp") {
				strPath = L"16,map_FanRenJiDi1_2.bmp,0|12,map_FanRenJiDi1_1.bmp,0|7,map_FanRenJiDi.bmp,0";
				if (movetoEX(strPath)) {
				}
			}
			if (strTask == L"task_BinHeBoss.bmp") {
				moveGong();
			}
			
		}
		if (strMap == L"map_FanRenJiDi.bmp") {
			bCheck = true;
			taskPath = 50;
			if (strTask == L"task_BinHeFanRen.bmp") {
				strPath = L"133,map_FanRenJiDi1_1.bmp,1";
				if (movetoEX(strPath)) {
					stateTask = true;
				}

			}
			if (strTask == L"task_BinHeFanRen2.bmp") {
				strPath = L"133,map_FanRenJiDi1_1.bmp,1|135,map_FanRenJiDi1_2.bmp,1";
				if (movetoEX(strPath)) {
					stateTask = true;
				}
			}
			if (strTask == L"task_BinHeBoss.bmp") {
				strPath = L"133,map_FanRenJiDi1_1.bmp,0|135,map_FanRenJiDi1_2.bmp,0";
				if (movetoEX(strPath)) {
					if (movetoX(136)) {
						for (size_t i = 0; i < 10; i++)
						{
							//获取y坐标138，92
							g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
							nY = y - nMapY;
							if (y > 93) {
								//按del键
								g_dm->KeyPress(35);
							}
							if (y < 93) {
								//下跳
								JumpDown();
							}
							if (nY == 92) {
								if (movetoX1(138)) {
									//查看地图是否进入
									for (size_t i = 0; i < 10; i++)
									{
										g_dm->KeyPress(38);
										Sleep(2000);
										g_dm->FindPic(0, 0, 470, 150, L"map_FanRenJiDi1_2.bmp", L"050505", 1, 0, &x, &y);
										if (x > 0) {
											stateTask = false;
											//moveGong();
										}
									}
									
								}
							}
						}
					}
				}
			}
		}
		if (strMap == L"map_FanRenJiDi1_1.bmp") {
			if (strTask == L"task_BinHeFanRenEnd.bmp") {
				strPath = L"7,map_FanRenJiDi.bmp,0";
				if (movetoEX(strPath)) {
					taskPath = 50;
					stateTask = false;
				}
			}
		}
		if (strMap == L"map_FanRenJiDi1_2.bmp") {
			taskPath = 50;
			if (strTask == L"task_BinHeFanRen2End.bmp") {
				strPath = L"12,map_FanRenJiDi1_1.bmp,0|7,map_FanRenJiDi.bmp,0";
				if (movetoEX(strPath)) {
					taskPath = 50;
					stateTask = false;
				}
			}
			if (strTask == L"task_BinHeBoss.bmp") {

				if (movetoX(136)) {
					for (size_t i = 0; i < 10; i++)
					{
						//获取y坐标138，92
						g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
						nY = y - nMapY;
						if (nY > 93) {
							//按del键
							//g_dm->KeyPress(35);
							g_dm->KeyDown(35);
							Sleep(RandomNumber(200, 300));
							g_dm->KeyUp(35);
							
							Sleep(RandomNumber(1000, 1500));
							g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
							nY = y - nMapY;
						}
						if (nY < 92) {
							//下跳
							JumpDown();
						}
						if (nY == 92) {
							strPath = L"138,map_BinHeBoss.bmp,0";
							if (movetoEX(strPath)) {
								break;
							}
							//if (y > 93) {
							//	//按del键
							//	//g_dm->KeyPress(35);
							//	g_dm->KeyDown(35);
							//	Sleep(RandomNumber(200, 300));
							//	g_dm->KeyUp(35);
							//}
							//if (y < 93) {
							//	//下跳
							//	JumpDown();
							//}
							//if (movetoX1(138)) {
							//	//查看地图是否进入
							//	for (size_t i = 0; i < 10; i++)
							//	{
							//		g_dm->KeyPress(38);
							//		Sleep(2000);
							//		g_dm->FindPic(0, 0, 470, 150, L"map_FanRenJiDi1_2.bmp", L"050505", 1, 0, &x, &y);
							//		if (x > 0) {
							//			stateTask = false;
							//			//moveGong();
							//		}
							//	}

							//}
						}
						Sleep(2000);
					}
				}

			}
		}
		//18
		if (!stateTask) {
			//移动到指定坐标
			//识别进行中任务
			//8, 150, 1026, 622
			if (taskPath != 0 && strMap !=L"map_HaiYangZhongYang.bmp") {
				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				long nX = x - nMapX;
				if (abs(taskPath - nX) >= 5) {
					if (movetoX(taskPath, strZhiXian)) {
						//if (k == 0) {
						//	for (size_t i = 0; i < RandomNumber(3,6) ; i++)
						//	{
						//		g_dm->KeyPress(16);
						//		Sleep(RandomNumber(200, 500));
						//	}
						//}
					}
				}
				if (bCheck) {
					for (size_t k = 0; k < 5; k++)
					{
						for (size_t i = 0; i < 10; i++)
						{

							CString strShu = g_dm->FindPicS(0, 0, 1024, 600, L"taskDengPao.bmp|taskend.bmp|taskShu.bmp||taskShu1.bmp", L"202020", 0.9, 0, &x, &y);
							if (x > 0) {
								//g_dm->delay(500);
								if (strShu == L"taskShu.bmp" || strShu == L"taskShu1.bmp") {
									g_dm->MoveTo(x - 15, y);
								}
								else {
									g_dm->MoveTo(x + 15, y + 10);
								}
								g_dm->LeftDoubleClick();
								g_dm->delay(800);
								g_dm->MoveTo(RandomNumber(150, 280), RandomNumber(5, 9));
								g_dm->delay(800);
								/*g_dm->MoveTo(0, 0);
								g_dm->delay(500);
								g_dm->MoveTo(RandomNumber(350, 460), RandomNumber(30,50));*/
								//TRACE(L"%d\n", x);
								//g_dm->delay(500);
								break;
							}
						}
						g_dm->FindPic(0, 0, 1024, 700, L"taskSucess.bmp|taskSucess1.bmp|taskSucess2.bmp", L"101010", 0.9, 0, &x, &y);
						if (x > 0) {
							g_dm->delay(1000);
							g_dm->MoveTo(x + 15, y + 10);
							g_dm->LeftClick();
							g_dm->delay(800);
							g_dm->MoveTo(RandomNumber(150, 270), RandomNumber(5, 9));
							g_dm->delay(1800);
							//g_dm->MoveTo(0, 0);
							//g_dm->delay(500);
							////g_dm->MoveTo(x + RandomNumber(50, 60), y- (200, 260));
							//g_dm->delay(500);
							break;
						}
					}
				}
				
			}

		}

		if (stateTask) {//是否已接任务
			k = 0;
			rectX = 75;
			JumpGong();
		}
		buxue(L"pgup");
		g_dm->MoveTo(RandomNumber(250, 300), RandomNumber(5, 9));
		//map_RuiEnCun
	}
	return 0;
}

unsigned WINAPI TaskJinHaiAn(PVOID pParam) {

	//识别地图
	//根据地图名称移动坐标
	long x, y;
	long hwnd = _wtol(g_dm->EnumWindow(0, L"MKSWindow#0", L"MKSEmbedded", 1 + 2));
	int ret = g_dm->BindWindowEx(hwnd, L"normal", L"normal", L"normal", L"", 0);
	g_dm->SetWindowState(hwnd, 12);

	Sleep(2000);
	//g_dm->FindPic(0, 0, 1280, 960, L"kaili_NPC.bmp|kaili_NPC1.bmp|kaili_NPC2.bmp", L"050505", 0.9, 0, &x, &y);
	//return;

	long nMapX, nMapY;
	//long nX, nY;
	g_dm->FindPic(0, 0, 200, 200, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);

	g_dm->FindPic(0, 0, 500, 380, L"minMapLeft.bmp", L"202020", 0.9, 0, &x, &y);
	m_mapArr[0] = x;
	m_mapArr[1] = 80;

	g_dm->FindPic(0, 0, 600, 400, L"minMap.bmp", L"000000", 0.98, 0, &x, &y);
	m_mapArr[2] = x + 15;
	m_mapArr[3] = y + 50;

	bool stateTask = false;
	CString strZhiXian,strPath,strTag;
	CString MoveTo;
	int i = 0,k=0;
	 
	while (bTaskFlag)
	{

		g_dm->FindPic(0, 0, 1024, 600, L"upWnd.bmp|ZhanTing1.bmp|ZhanTing1.bmp", L"050505", 0.96, 0, &x, &y);
		if (x > 0) {
			Sleep(8000);
		}

		//识别地图名
		g_dm->MoveTo(RandomNumber(150,280), RandomNumber(5, 9));


		//识别地图
		CString strMap = g_dm->FindPicS(0, 0, 470, 150, L"mapCaoCong3.bmp|mapCaoCong2.bmp|mapCaoCong1.bmp|mapDuJiaCun.bmp|mapHaiBian1.bmp|mapHaiBian2.bmp|mapHaiBian3.bmp|map_QianHai1.bmp|map_QianHai2.bmp|map_QianHai3.bmp|map_XiaoBoLang.bmp|map_XiaoBoLang2.bmp|map_DaBoLang.bmp", L"050505", 1, 0, &x, &y);

		//识别任务
		CString strTask = g_dm->FindPicS(176, 15, 1024, 311, L"task_BuXiangYuGan.bmp|task_BuXiangYuGanEnd.bmp|task_ZhongYaoDongXi.bmp|task_HuangJinHaiAn.bmp|task_HuangJinHaiAnEnd.bmp|task_WeiChiZhengJie.bmp|task_WeiChiZhengJieEnd.bmp|task_GuZhangDeYuanYin.bmp|task_GuZhangDeYuanYinEnd.bmp|task_HaiBianYuanZhuMing.bmp|task_HaiBianYuanZhuMingEnd.bmp|task_SiRenHaiTan.bmp|task_SiRenHaiTanEnd.bmp|task_YiShiJieZhi.bmp|task_YiShiJieZhiEnd.bmp|task_HeiSeBoLang.bmp|task_HeiSeBoLangEnd.bmp|task_YiSHiYouYongQuan.bmp|task_YiSHiYouYongQuan2.bmp|task_YiSHiYouYongQuanEnd.bmp|task_XinXianCaiLiao.bmp|task_XinXianCaiLiaoEnd.bmp|task_DiaoYuWang.bmp|task_DiaoYuWangEnd.bmp|task_BoLangJuanZhou.bmp|task_BoLangJuanZhou.bmp|task_BoLangJuanZhouEnd.bmp|task_HaiXingShuiLing.bmp|task_HaiXingShuiLingEnd.bmp|task_HaiLuoShuiLing.bmp|task_HaiLuoShuiLingEnd.bmp|task_JingRanBuShiyzm.bmp|task_YzmEnd.bmp", L"050505", 1, 0, &x, &y);
		//CString 
		//识别结束任务
		//8, 150, 1026, 622
		//strZhiXian = g_dm->FindPicS(8, 150, 1026, 622, L"mapCaoCong3.bmp", L"050505", 1, 0, &x, &y);
		strZhiXian = g_dm->FindPicS(8, 0, 1024, 622, L"task_BuXiangYuGanStart.bmp|moveTo_CaoCong2.bmp|task_ZhongYaoDongXiEnd.bmp|taskguzhangzhaoming.bmp|moveTo_HaiBian3.bmp|task_XunZhaoQianTIng.bmp|task_HeiShuiFaYuanDi.bmp", L"050505", 1, 0, &x, &y);
		int taskPath = 0;
		taskNext();
		for (size_t i = 0; i < 10; i++)
		{
			
			CString strShu = g_dm->FindPicS(0, 0, 1024, 600, L"taskDengPao.bmp|taskend.bmp||taskShu.bmp||taskShu1.bmp", L"202020", 0.9, 0, &x, &y);
			if (x > 0) {
				g_dm->delay(500);
				if (strShu == L"taskShu.bmp" || strShu == L"taskShu1.bmp") {
					g_dm->MoveTo(x - 15, y);
				}
				else {
					g_dm->MoveTo(x + 15, y + 10);
				}
				g_dm->LeftClick();
				g_dm->delay(800);
				g_dm->MoveTo(RandomNumber(150, 280), RandomNumber(5, 9));
				g_dm->delay(800);
				//g_dm->delay(1500);
				//g_dm->delay(500);
			//	g_dm->MoveTo(RandomNumber(400, 450), RandomNumber(30, 50));
				//TRACE(L"%d\n", x);
				//g_dm->delay(500);
				break;
			}
		}
		//草丛3任务
		if (strMap == L"mapCaoCong3.bmp") {
			taskPath = 40;
			//查看任务是否结束
			//
			if ((strTask == L"task_BuXiangYuGan.bmp" || strZhiXian == L"task_BuXiangYuGanStart.bmp") && !stateTask) {//任务开始
				i = 0;
				stateTask = true;
			}
			if (strTask == L"task_BuXiangYuGanEnd.bmp") {//任务结束移动地图
				/*i = 0;
				stateTask = false;
				strPath = L"146,haiancaocong1.bmp,1|130,huangjinhaian.bmp,1|80,huangjinhaian.bmp,1";
				movetoEX(strPath);*/
				strTag = L"移动到飞行员";
				stateTask = false;
			}
			if (strTag == L"移动到草丛2"|| strZhiXian == L"moveTo_CaoCong2.bmp"|| strZhiXian == L"moveTo_CaoCong2_1.bmp"|| strZhiXian == L"moveTo_CaoCong2") {
				
				strPath = L"148,mapCaoCong2.bmp,1";
				if (movetoEX(strPath)) {
					stateTask = false;
				}
				//if (movetoX(149)) {
				//	g_dm->KeyPress(38);
				//	Sleep(3300);
				//	strZhiXian = "";
				//	stateTask = false;
				//	i = 0;
				//	g_dm->FindPicS(0, 0, 470, 150, L"mapCaoCong3.bmp", L"050505", 1, 0, &x, &y);
				//	if (x == -1) {
				//		continue;
				//	}
				//}
			}
		
			npcClick(L"jiashi_NPC", 10, 0);
			Sleep(1500);
			g_dm->FindPic(0, 0, 1024, 700, L"haitan3End.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				strZhiXian = L"moveTo_CaoCong2";
				strTag = L"移动到草丛2";
			}
			g_dm->FindPic(0, 0, 1280, 960, L"endWnd.bmp", L"101010", 0.9, 0, &x, &y);
			if (x > 0) {
				g_dm->MoveTo(x, y);
				g_dm->LeftClick();
			}

		}
		//草丛2任务
		if (strMap == L"mapCaoCong2.bmp") {
			taskPath = 40;
			if (strTask == L"task_ZhongYaoDongXi.bmp" && !stateTask) {
				stateTask = true;
			}
			if (strZhiXian == L"task_ZhongYaoDongXiEnd.bmp") {//任务结束移动地图
				//i = 0;
				strPath = L"146,haiancaocong1.bmp,1|130,huangjinhaian.bmp,1|80,huangjinhaian.bmp,1";
				if (movetoEX(strPath)) {
					stateTask = false;
				}
				
			}
		}

		if (strMap == L"mapCaoCong1.bmp") {//草丛1
			k = 1;
			//taskPath = 40;
			if (strTask == L"task_HuangJinHaiAnEnd.bmp") {
				strPath = L"129,huangjinhaian.bmp,0|80,huangjinhaian.bmp,0";
				movetoEX(strPath);
				stateTask = false;
			}
		}

		if (strMap == L"mapDuJiaCun.bmp") {//度假村
			k = 1;
			g_dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"101010", 0.95, 0, &x, &y);
			if (x > 0) {
				g_dm->KeyPress(73);//关闭背包
				Sleep(2000);
			}
			taskPath = 80;
			if (strTask == L"task_HuangJinHaiAn.bmp" && !stateTask) {
				//stateTask = true;
				strPath = L"10,haiancaocong1.bmp,0";
				if (movetoEX(strPath)) {
					stateTask = true;
				}
			}
			if (strTask == L"task_WeiChiZhengJie.bmp" && !stateTask) {
				strPath = L"148,haianhaibian1.bmp,0";
				if (movetoEX(strPath)) {
					stateTask = true;
				}
			}
			if (strZhiXian == L"taskguzhangzhaoming.bmp" && !stateTask) {
				strPath = L"148,haianhaibian1.bmp,0|150,haianhaibian2.bmp,0";
				movetoEX(strPath);
				stateTask = false;
			}

			g_dm->FindPic(176, 15, 1024, 311, L"task_YiSHiYouYongQuan1End.bmp|task_YiSHiYouYongQuan1_2End.bmp", L"050505", 1, 0, &x, &y);

			if (strTask == L"task_YiSHiYouYongQuan2.bmp" || x>0) {//遗失游泳圈2任务，红色游泳圈结束 移动到浅海2
				//g_TaskName = L"";
				strPath = L"149,haianhaibian1.bmp,0|151,haianhaibian2.bmp,0|148,haianhaibian3.bmp,0|148,xianhai1_MAP.bmp,0|148,map_QianHai2.bmp,1";
				if (movetoEX(strPath)) {
					stateTask = true;
				}
			}


			if (strTask == L"task_YiSHiYouYongQuan.bmp") {
				strPath = L"149,haianhaibian1.bmp,0|151,haianhaibian2.bmp,0|148,haianhaibian3.bmp,0|148,xianhai1_MAP.bmp,0";
				if (movetoEX(strPath)) {
					stateTask = true;
				}
			}


		}

		if (strMap == L"mapHaiBian1.bmp") {//海边1
			//taskPath = 40;
			if (strTask == L"task_WeiChiZhengJieEnd.bmp") {
				strPath = L"26,huangjinhaian.bmp,0|80,huangjinhaian.bmp,0";
				movetoEX(strPath);
				stateTask = false;
			}
			k = 1;
			//task_WeiChiZhengJieEnd
		}

		if (strMap == L"mapHaiBian2.bmp") {//海岸海边2
			taskPath = RandomNumber(40,50);
			if ((strTask == L"task_GuZhangDeYuanYin.bmp" || strTask == L"task_SiRenHaiTan.bmp" || strTask == L"task_HaiBianYuanZhuMing.bmp") && !stateTask) {
				stateTask = true;
				if (strTask == L"task_SiRenHaiTan.bmp") {
					strPath = L"147,haianhaibian3.bmp,0";
					movetoEX(strPath);
				}
			}
			if (strTask == L"task_GuZhangDeYuanYinEnd.bmp" || strTask == L"task_HaiBianYuanZhuMingEnd.bmp") {
				stateTask = false;
			}
			if (strZhiXian == L"moveTo_HaiBian3.bmp") {
				strPath = L"147,haianhaibian3.bmp,0";
				movetoEX(strPath);
				stateTask = false;
			}
		}

		if (strMap == L"mapHaiBian3.bmp") {
			taskPath = RandomNumber(120, 125);
			if (strTask == L"task_SiRenHaiTanEnd.bmp") {
				stateTask = false;
				strPath = L"10,haianhaibian2.bmp,0";
				movetoEX(strPath);
			}
			if (strTask == L"task_YiShiJieZhi.bmp" && !stateTask) {
				stateTask = true;
			}
			if (strTask == L"task_YiShiJieZhiEnd.bmp") {
				stateTask = false;
			}
			if (strZhiXian == L"task_XunZhaoQianTIng.bmp") {
				strPath = L"146,map_QianHai1.bmp,0";
				movetoEX(strPath);
				stateTask = false;
			}

		}

		if (strMap == L"map_QianHai1.bmp") {
			taskPath = 69;
			if (strTask == L"task_HeiSeBoLang.bmp" && !stateTask) {
				stateTask = true;
			}
			if (strTask == L"task_HeiSeBoLangEnd.bmp") {
				strPath = L"148,map_QianHai2.bmp,0";
				if (movetoEX(strPath)) {
					for (size_t k = 0; k < 10; k++)
					{
						strMap = g_dm->FindPicS(0, 0, 470, 150, L"mapCaoCong3.bmp|mapCaoCong2.bmp|mapCaoCong1.bmp|mapDuJiaCun.bmp|mapHaiBian1.bmp|mapHaiBian2.bmp|mapHaiBian3.bmp|map_QianHai1.bmp|map_QianHai2.bmp|map_QianHai3.bmp|map_XiaoBoLang.bmp|map_XiaoBoLang2.bmp|map_DaBoLang.bmp", L"050505", 1, 0, &x, &y);
						if (strMap == L"mapDuJiaCun.bmp") {
							continue;
						}
						else {
							g_dm->FindPic(0, 0, 800, 600, L"bagWnd.bmp", L"050505", 0.9, 0, &x, &y);
							if (x > 0) {//存在
								Sleep(500);

								long x1, y1;
								g_dm->FindPic(0, 0, 800, 600, L"wupinsuoxiao.bmp", L"050505", 0.9, 0, &x1, &y1);
								if (x1 > 0) {
									Sleep(500);
									g_dm->MoveTo(5, 5);
									Sleep(500);
									g_dm->MoveTo(x1 + RandomNumber(3, 8), y1 + RandomNumber(3, 8));
									Sleep(1000);
									g_dm->LeftClick();
									Sleep(1500);
								}
								g_dm->FindPic(0, 0, 800, 600, L"bagWnd.bmp", L"050505", 0.9, 0, &x, &y);
								g_dm->FindPic(0, 0, 800, 600, L"wupinWnd.bmp", L"050505", 0.9, 0, &x1, &y1);
								if (x1 == -1) {
									g_dm->MoveTo(5, 5);
									Sleep(500);
									g_dm->MoveTo(x - RandomNumber(15, 20), y + 30);
									Sleep(1000);
									g_dm->LeftClick();
								}


								Sleep(2000);
								g_dm->FindPic(0, 0, 1024, 700, L"backKaPian.bmp", L"050505", 0.9, 0, &x, &y);
								if (x > 0) {
									g_dm->MoveTo(5, 5);
									Sleep(500);
									g_dm->MoveTo(x + RandomNumber(5, 15), y + RandomNumber(5, 15));
									Sleep(1000);
									g_dm->LeftDoubleClick();
									Sleep(4000);
									g_dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"050505", 1, 0, &x, &y);
									if (x > 0) {
										g_dm->KeyPress(73);//关闭背包
										Sleep(2000);
										continue;
									}
								}
							}
							else {//不存在
								Sleep(500);
								g_dm->KeyPress(73);
								Sleep(500);
							}
						}

					}

				}
				stateTask = false;
			}

			if (strTask == L"task_YiSHiYouYongQuan.bmp") {
				stateTask = true;
			}
			g_dm->FindPic(176, 15, 1024, 311, L"task_YiSHiYouYongQuan1End.bmp|task_YiSHiYouYongQuan1_2End.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				strPath = L"148,map_QianHai2.bmp,1";
				if (movetoEX(strPath)) {
					stateTask = true;
				}
			}

		}
		if (strMap == L"map_QianHai2.bmp") {

			g_dm->FindPic(176, 15, 1024, 311, L"task_YiSHiYouYongQuan1End.bmp|task_YiSHiYouYongQuan2_1.bmp|task_YiSHiYouYongQuan2.bmp", L"050505", 1, 0, &x, &y);
			if (x > 0) {
				stateTask = true;
			}
			g_dm->FindPic(176, 15, 1024, 311, L"task_YiSHiYouYongQuan2End.bmp", L"050505", 1, 0, &x, &y);
			if (strTask == L"task_YiSHiYouYongQuanEnd.bmp" || x>0) {
				taskPath = 50;
				stateTask = false;
			}
			if (strTask == L"task_XinXianCaiLiao.bmp") {
				//taskPath = 50;
				strPath = L"148,xianhai3_MAP.bmp,0";
				if (movetoEX(strPath)) {
					stateTask = true;
				}
			}
			
		}
		if (strMap == L"map_QianHai3.bmp") {
			taskPath = 25;
			if (strTask == L"task_XinXianCaiLiaoEnd.bmp" || strTask == L"task_DiaoYuWangEnd.bmp") {
				stateTask = false;
			}
			if (strTask == L"task_DiaoYuWang.bmp" && !stateTask) {
				stateTask = true;
			}
			if (strTask == L"task_BoLangJuanZhou.bmp") {
				strPath = L"148,map_XiaoBoLang.bmp,0";
				if (movetoEX(strPath)) {
					stateTask = true;
				}
				
			}
			//if (strTask == L"task_GuLiWeiJi.bmp") {//孤立危机
			//	strPath = L"148,map_XiaoBoLang.bmp,0";
			//	if (movetoEX(strPath)) {
			//		stateTask = true;
			//	}

			//}
			if (strTask == L"task_HaiXingShuiLing.bmp") {//海星绿水灵
				strPath = L"148,map_XiaoBoLang.bmp,0|148,map_XiaoBoLang2.bmp,0";
				if (movetoEX(strPath)) {
					stateTask = true;
				}

			}
			if (strZhiXian == L"task_HeiShuiFaYuanDi.bmp") {
				strPath = L"148,map_XiaoBoLang.bmp,0|148,map_XiaoBoLang2.bmp,0|146,map_DaBoLang.bmp,0";
				if (movetoEX(strPath)) {
					taskPath = 69;
					stateTask = false;
				}
			}
			
		}

		if (strMap == L"map_XiaoBoLang.bmp") {//小波浪1
			if (strTask == L"task_BoLangJuanZhouEnd.bmp") {
				strPath = L"10,map_QianHai3.bmp,0";
				if (movetoEX(strPath)) {
					stateTask = false;
				}
			}
			
		}
		if (strMap == L"map_XiaoBoLang2.bmp") {//小波浪2
			if (strTask == L"task_HaiXingShuiLingEnd.bmp") {
				strPath = L"146,map_DaBoLang.bmp,0";
				if (movetoEX(strPath)) {
					stateTask = false;
				}
			}
		}
		if (strMap == L"map_DaBoLang.bmp") {
			taskPath = 80;
			if (strTask == L"task_HaiXingShuiLingEnd.bmp" && !stateTask) {
					stateTask = true;
			}
			if (strTask == L"task_HaiLuoShuiLing.bmp") {
				stateTask = false;
			}
			if (strTask == L"task_HaiLuoShuiLingEnd.bmp") {
				strPath = L"10,map_XiaoBoLang2.bmp,0|10,map_XiaoBoLang.bmp,0|10,map_QianHai3.bmp,0";
				if (movetoEX(strPath)) {
					stateTask = false;
				}
			}if (strTask == L"task_JingRanBuShiyzm.bmp") {
				stateTask = true;
			}
			if (strTask == L"task_YzmEnd.bmp") {
				//OnBnClickedButton9();
				AfxMessageBox(L"任务结束");
				
			}
			
		}
		//
		if (!stateTask) {
			//移动到指定坐标
			//识别进行中任务
			//8, 150, 1026, 622
			if (taskPath != 0) {
				g_dm->FindPic(0, 0, 600, 600, L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
				long nX = x - nMapX;
				if (abs(taskPath - nX) >= 5) {
					if (movetoX(taskPath, strZhiXian)) {
						//if (k == 0) {
						//	for (size_t i = 0; i < RandomNumber(3,6) ; i++)
						//	{
						//		g_dm->KeyPress(16);
						//		Sleep(RandomNumber(200, 500));
						//	}
						//}
					}
				}

				for (size_t k = 0; k < 5; k++)
				{
					for (size_t i = 0; i < 10; i++)
					{

						CString strShu = g_dm->FindPicS(0, 0, 1024, 600, L"taskDengPao.bmp|taskend.bmp||taskShu.bmp||taskShu1.bmp", L"202020", 0.9, 0, &x, &y);
						if (x > 0) {
							g_dm->delay(500);
							if (strShu == L"taskShu.bmp" || strShu == L"taskShu1.bmp") {
								g_dm->MoveTo(x - 15, y);
							}
							else {
								g_dm->MoveTo(x + 15, y + 10);
							}
							g_dm->LeftClick();
							g_dm->delay(800);
							g_dm->MoveTo(RandomNumber(150, 280), RandomNumber(5, 9));
							g_dm->delay(800);
							/*g_dm->MoveTo(0, 0);
							g_dm->delay(500);
							g_dm->MoveTo(RandomNumber(350, 460), RandomNumber(30,50));*/
							//TRACE(L"%d\n", x);
							//g_dm->delay(500);
							break;
						}
					}
					g_dm->FindPic(0, 0, 1024, 700, L"taskSucess.bmp|taskSucess1.bmp", L"101010", 0.9, 0, &x, &y);
					if (x > 0) {
						g_dm->delay(1000);
						g_dm->MoveTo(x + 15, y + 10);
						g_dm->LeftClick();
						g_dm->delay(800);
						g_dm->MoveTo(RandomNumber(150, 270), RandomNumber(5, 9));
						g_dm->delay(1800);
						//g_dm->MoveTo(0, 0);
						//g_dm->delay(500);
						////g_dm->MoveTo(x + RandomNumber(50, 60), y- (200, 260));
						//g_dm->delay(500);
						break;
					}
				}
			}

		}
		if (stateTask) {//是否已接任务
			k = 0;
			JumpGong();
		}
		
		g_dm->MoveTo(RandomNumber(250, 300), RandomNumber(30, 50));
		//g_dm->FindPic(0, 0, 470, 150, L"taskDengPao.bmp|taskend.bmp", L"101010", 0.9, 0, &x, &y);

		//g_dm->delay(2000);
		//g_dm->MoveTo(250,  100);
	}
	return 0;
}
void moveGong() {
	moveGong(L"shift");
}
void moveGong(CString strKey) {
	long x, y;
	int rectX = 40;
	int Keyboard = RandomNumber(1, 2) == 1 ? 37 : 39;
	for (size_t i = 0; i < RandomNumber(10, 15); i++)
	{
		g_dm->FindPic(0, 0, m_mapArr[2], m_mapArr[3], L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);

			if (x > m_mapArr[2] - rectX) {
				Keyboard = mapKey[L"left"];
				g_dm->KeyUp(mapKey[L"right"]);
				Sleep(RandomNumber(100, 200));
				g_dm->KeyDown(mapKey[L"left"]);
			}
			if (x < m_mapArr[0] + rectX) {
				Keyboard = mapKey[L"right"];

				g_dm->KeyUp(mapKey[L"left"]);
				Sleep(RandomNumber(100, 200));
				g_dm->KeyDown(Keyboard);
			}
			
		//if (i % 5 == 0) {
		//	g_dm->KeyUp(Keyboard);
		//	Sleep(RandomNumber(300, 500));
		//	Keyboard = Keyboard == 37 ? 39 : 37;
		//	g_dm->KeyDown(Keyboard);
		//}
		g_dm->KeyDown(mapKey[strKey]);
		Sleep(RandomNumber(1000, 1500));
		g_dm->KeyUp(mapKey[strKey]);
		Sleep(RandomNumber(1000, 1500));


		//g_dm->FindPic(0, 0, 900, 1200, L"xue.bmp", L"050505", 0.90, 0, &x, &y);
		//if (x == -1) {
		//	int nSel = ((CComboBox*)g_Knight_main_cwnd->GetDlgItem(IDC_COMBO4))->GetCurSel();
		//	if (nSel != -1) {
		//		((CComboBox*)g_Knight_main_cwnd->GetDlgItem(IDC_COMBO4))->GetLBText(nSel, strKey);
		//		g_dm->KeyUp(Keyboard);
		//		RandomNumber(110, 180);
		//		g_dm->KeyDown(mapKey[strKey]);
		//		RandomNumber(90, 180);
		//		g_dm->KeyUp(mapKey[strKey]);
		//		RandomNumber(300, 900);
		//		g_dm->KeyDown(Keyboard);
		//	}
		//}
		//g_dm->FindPic(0, 0, 900, 1200, L"lan.bmp", L"101010", 0.90, 0, &x, &y);
		//if (x == -1) {
		//	int nSel = ((CComboBox*)g_Knight_main_cwnd->GetDlgItem(IDC_COMBO8))->GetCurSel();
		//	if (nSel != -1) {
		//		((CComboBox*)g_Knight_main_cwnd->GetDlgItem(IDC_COMBO8))->GetLBText(nSel, strKey);
		//		g_dm->KeyUp(Keyboard);
		//		RandomNumber(110, 180);
		//		g_dm->KeyDown(mapKey[strKey]);
		//		RandomNumber(90, 180);
		//		g_dm->KeyUp(mapKey[strKey]);
		//		RandomNumber(300, 900);
		//		g_dm->KeyDown(Keyboard);
		//	}
		//}
	}
	g_dm->KeyUp(mapKey[L"right"]);
	g_dm->KeyUp(mapKey[L"left"]);
	//g_dm->KeyUp(17);



}

void Delay(int time) {
	long x, y;
	g_dm->FindPic(0, 0, 200, 200, L"miniMap.bmp", L"050505", 0.9, 0, &x, &y);
	if (x == -1 || x > 20) {
		Sleep(5000);
	}
	Sleep(time);
}

unsigned WINAPI SubTaskThread(PVOID pParam) {
	long x, y, nMapX, nMapY, nX, nPath;
	//long nX, nY;
	g_ckdm->FindPic(0, 0, 200, 200, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);
	//int i = 0;
	long hwnd = _wtol(g_ckdm->EnumWindow(0, L"MKSWindow#0", L"MKSEmbedded", 1 + 2));
	int ret = g_ckdm->BindWindowEx(hwnd, L"normal", L"normal", L"normal", L"", 0);
	g_ckdm->SetWindowState(hwnd, 12);
	strTaskName = L"task_BuXiangYuGan.bmp|haitan3End.bmp|task_BuXiangYuGanEnd.bmp|task_ZhongYaoDongXi.bmp|task_ZhongYaoDongXiEnd.bmp|task_HuangJinHaiAn.bmp|task_HuangJinHaiAnEnd.bmp|task_WeiChiZhengJie.bmp|task_WeiChiZhengJieEnd.bmp|taskguzhangzhaoming.bmp|task_GuZhangDeYuanYin.bmp|task_GuZhangDeYuanYinEnd.bmp|task_HaiBianYuanZhuMing.bmp|task_HaiBianYuanZhuMingEnd.bmp|task_SiRenHaiTan.bmp|task_SiRenHaiTanEnd.bmp|task_YiShiJieZhi.bmp|task_YiShiJieZhiEnd.bmp|task_HeiSeBoLang.bmp|task_HeiSeBoLangEnd.bmp|task_YiSHiYouYongQuan.bmp|task_YiSHiYouYongQuan2.bmp|task_YiSHiYouYongQuanEnd.bmp|task_XinXianCaiLiao.bmp|task_XinXianCaiLiaoEnd.bmp|task_DiaoYuWang.bmp|task_DiaoYuWangEnd.bmp|task_BoLangJuanZhou.bmp|task_BoLangJuanZhou.bmp|task_BoLangJuanZhouEnd.bmp|task_HaiXingShuiLing.bmp|task_HaiXingShuiLingEnd.bmp|task_HaiLuoShuiLing.bmp|task_HaiLuoShuiLingEnd.bmp|task_JingRanBuShiyzm.bmp|task_YzmEnd.bmp|task_XunZhaoQianTIng.bmp|task_YiSHiYouYongQuan1End.bmp|task_YiSHiYouYongQuan1_2End.bmp|task_YiSHiYouYongQuan2End.bmp|task_HeiShuiFaYuanDi.bmp|task_YuanZhuMingEnd.bmp|moveTo_HaiBian3.bmp|task_XunZhaoQianTIng.bmp|task_JinHaiAnHuiCheng.bmp|task_JinHaiAnBoss.bmp";
	int n=0;
	g_ckdm->MoveTo(RandomNumber(250, 300), RandomNumber(5, 9));
	Sleep(500);
	g_ckdm->MoveTo(RandomNumber(418, 621), RandomNumber(709, 776));
	g_ckdm->LeftDoubleClick();
	while (bTaskFlag)
	{
		//g_dm->FindPic(0, 0, 200, 200, L"miniMap.bmp", L"050505", 1, 0, &nMapX, &nMapY);

		//g_ckdm->MoveTo(RandomNumber(250, 300), RandomNumber(5, 9));
		
		g_ckdm->FindPic(0, 0, 1024, 700, L"taskwancheng.bmp", L"101010", 0.95, 0, &x, &y);
		if (x > 0) {
			g_TaskState = false;
		}
		//处理对话框
		
		g_ckdm->FindPic(0, 0, 1024, 700, L"taskOK.bmp", L"101010", 0.9, 0, &x, &y);
		if (x > 0) {
			g_ckdm->MoveTo(RandomNumber(250, 300), RandomNumber(5, 9));
			Sleep(1500);
			g_ckdm->MoveTo(x, y);
			g_ckdm->LeftClick();
			Sleep(1000);
			//g_ckdm->MoveTo(RandomNumber(150, 280), RandomNumber(5, 9));
			//Sleep(1000);
			g_ckdm->MoveTo(x + 10, y - RandomNumber(250, 300));
			Sleep(500);
	/*		g_ckdm->delay(800);
			g_ckdm->MoveTo(RandomNumber(150, 280), RandomNumber(5, 9));
			g_ckdm->delay(800);*/
			//g_ckdm->MoveTo(x + 10, y - RandomNumber(250, 300));
		}
		for (size_t i = 0; i < 10; i++)
		{
			g_ckdm->FindPic(0, 0, 1024, 700, L"endWnd.bmp|next.bmp|next1.bmp", L"101010", 0.9, 0, &x, &y);
			if (x > 0) {
				Sleep(300);
				g_ckdm->KeyPress(32);
			}
			if (i > 9) {
				g_ckdm->FindPic(0, 0, 1024, 700, L"endWnd.bmp", L"101010", 0.9, 0, &x, &y);
				if (x > 0) {
					for (size_t k = 0; k < 3; k++)
					{
						g_ckdm->FindPic(0, 0, 1024, 700, L"endWnd.bmp", L"101010", 0.9, 0, &x, &y);
						if (x > 0) {
							g_ckdm->MoveTo(RandomNumber(250, 300), RandomNumber(5, 9));
							//g_ckdm->MoveTo(0, 0);
							Sleep(500);
							g_ckdm->MoveTo(x + 10, y + 5);
							g_ckdm->LeftClick();
							Sleep(1000);
						}
					}
				}
			}
		}

		g_ckdm->FindPic(0, 0, 1024, 700, L"jieshouTask.bmp|taskQueRen.bmp|task_ZhuanZhi.bmp|yes.bmp|jieshouTask1.bmp", L"101010", 0.9, 0, &x, &y);
		if (x > 0) {//接受任务
			g_ckdm->MoveTo(RandomNumber(250, 300), RandomNumber(5, 9));
			//g_ckdm->MoveTo(0, 0);
			Sleep(500);
			g_ckdm->MoveTo(x + 10, y + 5);
			g_ckdm->LeftClick();
			Sleep(1000);
			//g_ckdm->MoveTo(RandomNumber(150, 280), RandomNumber(5, 9));
		//	Sleep(1000);
			/*g_ckdm->MoveTo(x + 10, y - RandomNumber(250, 300));
			Sleep(500);*/
			g_ckdm->delay(800);
			//g_ckdm->MoveTo(RandomNumber(150, 280), RandomNumber(5, 9));
			/*g_ckdm->delay(800);*/
			//g_ckdm->MoveTo(x + 10, y - RandomNumber(250,300));

		}

		if (!g_TaskState) {
			g_ckdm->FindPic(0, 0, 1024, 700, L"endWnd.bmp|next.bmp|next1.bmp|jieshouTask.bmp|taskQueRen.bmp|task_ZhuanZhi.bmp|yes.bmp|jieshouTask1.bmp", L"101010", 0.9, 0, &x, &y);
			if (x == -1) {
				//点击任务  攻击状态为假时寻找任务
				CString strShu = g_ckdm->FindPicS(0, 0, 1024, 600, L"taskDengPao.bmp|taskend.bmp|taskShu.bmp||taskShu1.bmp", L"202020", 0.9, 0, &x, &y);
				if (x > 0 && x>60) {
					g_ckdm->MoveTo(RandomNumber(250, 300), RandomNumber(5, 9));
					g_ckdm->delay(500);
					if (strShu == L"taskShu.bmp" || strShu == L"taskShu1.bmp") {
						g_ckdm->MoveTo(x - 15, y);
					}
				else {
						g_ckdm->MoveTo(x + 15, y + 10);
					}
					g_ckdm->LeftClick();
					Sleep(1000);
					g_ckdm->MoveTo(x + 10, y - RandomNumber(250, 300));
					Sleep(1000);
				}
				g_ckdm->FindPic(0, 0, 1024, 700, L"taskSucess.bmp|taskSucess1.bmp|taskSucess2.bmp", L"101010", 0.9, 0, &x, &y);
				if (x > 50 && g_TaskName == "") {
					g_ckdm->MoveTo(RandomNumber(250, 300), RandomNumber(5, 9));
					//g_ckdm->MoveTo(0, 0);
					g_ckdm->MoveTo(x + 15, y + 10);
					Sleep(500);
					g_ckdm->LeftClick();
					Sleep(1000);
					////g_ckdm->MoveTo(RandomNumber(150, 280), RandomNumber(5, 9));
					//Sleep(1000);
					g_ckdm->MoveTo(x + 10, y - RandomNumber(250, 300));
					Sleep(500);
					g_sucessState = true;
					//Sleep(20000);
				}
				g_ckdm->FindPicS(0, 0, 470, 150, L"mapCaoCong3.bmp", L"050505", 1, 0, &x, &y);
				if (x > 0) {
					npcClick(L"jiashi_NPC", 10, 0);
				}
			}

			n++;
			if (n % 5 == 0) {
				g_ckdm->MoveTo(RandomNumber(250, 300), RandomNumber(5, 9));
				Sleep(500);
				g_ckdm->MoveTo(RandomNumber(418, 621), RandomNumber(709, 776));
				g_ckdm->LeftClick();
			}

		}
		g_TaskName = g_ckdm->FindPicS(176, 15, 1024, 711, strTaskName, L"050505", 1, 0, &x, &y);
		if (g_TaskName != "") {
	 		g_TaskName.Replace(L".bmp", L"");
			
			for (size_t i = 0; i < 3; i++)
			{
				g_ckdm->FindPic(0, 0, 1024, 700, L"endWnd.bmp|next.bmp|next1.bmp", L"101010", 0.9, 0, &x, &y);
				if (x > 0) {
					Sleep(300);
					g_ckdm->KeyPress(32);
				}
			}
			if (g_sucessState) {
				Sleep(5000);
				g_sucessState = false;
			}
		}
		Sleep(100);
		buxue(L"pgdn");
		BuLan(L"pgup");
	}

	return 0;
}



unsigned WINAPI MainTaskThread(PVOID pParam) {
	long x, y;
	long hwnd = _wtol(g_dm->EnumWindow(0, L"MKSWindow#0", L"MKSEmbedded", 1 + 2));
	int ret = g_dm->BindWindowEx(hwnd, L"normal", L"normal", L"normal", L"", 0);
	g_dm->SetWindowState(hwnd, 12);

	Sleep(2000);
	//g_dm->FindPic(0, 0, 1280, 960, L"kaili_NPC.bmp|kaili_NPC1.bmp|kaili_NPC2.bmp", L"050505", 0.9, 0, &x, &y);
	//return;

	long nMapX, nMapY;
	//long nX, nY;
	g_dm->FindPic(0, 0, 200, 200, L"miniMap.bmp", L"050505", 0.9, 0, &nMapX, &nMapY);

	g_dm->FindPic(0, 0, 500, 380, L"minMapLeft.bmp", L"202020", 0.9, 0, &x, &y);
	m_mapArr[0] = x;
	m_mapArr[1] = 80;

	g_dm->FindPic(0, 0, 600, 400, L"minMap.bmp", L"000000", 0.98, 0, &x, &y);
	m_mapArr[2] = x + 15;
	m_mapArr[3] = y + 50;

	bool stateTask = false;
	CString strZhiXian, strPath, strTag;
	CString MoveTo;
	int i = 0, k = 0;
	while (bTaskFlag)
	{
		strMapName = L"mapCaoCong3.bmp|mapCaoCong2.bmp|mapCaoCong1.bmp|mapDuJiaCun.bmp|mapHaiBian1.bmp|mapHaiBian2.bmp|mapHaiBian3.bmp|map_QianHai1.bmp|map_QianHai2.bmp|map_QianHai3.bmp|map_XiaoBoLang.bmp|map_XiaoBoLang2.bmp|map_DaBoLang.bmp";
		CString str_MapName = g_dm->FindPicS(0, 0, 470, 150, strMapName, L"050505", 1, 0, &x, &y);
		str_MapName.Replace(L".bmp", L"");
		
		//taskNext();

		if (g_Task == L"金沙滩") {
			RunTaskJin(str_MapName);
		}
		else if (g_Task == L"列那海峡") {

		}
		if (g_TaskState) {
			JumpGong();
			//moveRandGong();
		}
		else {
			g_dm->FindPic(0, 0, 1024, 700, L"endWnd.bmp|next.bmp", L"101010", 0.9, 0, &x, &y);
			if (x==-1) {
				moveX(nXPath);
			}

		}
	}
	
	
	return 0;


}


void RunTaskJin(CString str_mapName) {
	long x, y;
	CString strPath;
	if (str_mapName == L"mapCaoCong3") {//草丛3
		nXPath = 40;
		RunTask(L"task_BuXiangYuGan", 0, L"", true);
		RunTask(L"task_BuXiangYuGanEnd", 0, L"", false);
		RunTask(L"haitan3End", 0, L"148,mapCaoCong2.bmp,1", false);
	}
	else if (str_mapName == L"mapCaoCong2") {//海岸草丛2
		RunTask(L"task_ZhongYaoDongXi", 0, L"", true);
		RunTask(L"task_ZhongYaoDongXiEnd", 0, L"146,haiancaocong1.bmp,1|130,huangjinhaian.bmp,1|80,huangjinhaian.bmp,1", false);

	}
	else if (str_mapName == L"mapCaoCong1") {//海岸草丛3
		RunTask(L"task_HuangJinHaiAnEnd", 0, L"129,huangjinhaian.bmp,0|80,huangjinhaian.bmp,0", false);
	}
	else if (str_mapName == L"mapDuJiaCun") {//度假村
		nXPath = 80;
		g_dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"101010", 0.95, 0, &x, &y);
		if (x > 0) {
			g_dm->KeyPress(73);//关闭背包
			Sleep(2000);
		}
		RunTask(L"task_HuangJinHaiAn", 0, L"10,haiancaocong1.bmp,0", true);
		RunTask(L"task_WeiChiZhengJie", 0, L"148,haianhaibian1.bmp,0", true);
		RunTask(L"taskguzhangzhaoming", 0, L"148,haianhaibian1.bmp,0|150,haianhaibian2.bmp,0", false);

		g_dm->FindPic(176, 15, 1024, 311, L"task_YiSHiYouYongQuan1End.bmp|task_YiSHiYouYongQuan1_2End.bmp", L"050505", 1, 0, &x, &y);
		
		if (g_TaskName == L"task_YiSHiYouYongQuan2" || x>0) {//遗失游泳圈2任务，红色游泳圈结束 移动到浅海2
			strPath = L"149,haianhaibian1.bmp,0|151,haianhaibian2.bmp,0|148,haianhaibian3.bmp,0|148,xianhai1_MAP.bmp,0|148,xianhai2_MAP.bmp,0";
			if (movetoEX(strPath)) {
				g_TaskState = true;
			}
		}


		if (g_TaskName == L"task_YiSHiYouYongQuan.bmp") {
			strPath = L"149,haianhaibian1.bmp,0|151,haianhaibian2.bmp,0|148,haianhaibian3.bmp,0|148,xianhai1_MAP.bmp,0";
			if (movetoEX(strPath)) {
				g_TaskState = true;
			}
		}

		if (g_TaskName == L"task_JinHaiAnBoss") {//移动到boss
			strPath = L"149,haianhaibian1.bmp,0|151,haianhaibian2.bmp,0|148,haianhaibian3.bmp,0|148,xianhai1_MAP.bmp,0|148,xianhai2_MAP.bmp,0|148,map_XiaoBoLang.bmp,0|148,map_XiaoBoLang2.bmp,0|146,map_DaBoLang.bmp,0";
			if (movetoEX(strPath)) {
				g_TaskState = false;
				AfxMessageBox(L"任务完成");
				g_dm->SetWindowState((long)AfxGetMainWnd()->m_hWnd, 12);
				bTaskFlag = false;
			}
		}
	}
	else if (str_mapName == L"mapHaiBian1")//海岸海边1
	{
		RunTask(L"task_WeiChiZhengJieEnd", 0, L"26,huangjinhaian.bmp,0|80,huangjinhaian.bmp,0", false);
	}
	else if (str_mapName == L"mapHaiBian2") {//海岸海边2
		nXPath = 50;
		RunTask(L"task_GuZhangDeYuanYin", 0, L"", true);
		RunTask(L"task_SiRenHaiTan", 0, L"", true);
		RunTask(L"task_HaiBianYuanZhuMing", 0, L"", true);
		RunTask(L"task_SiRenHaiTan", 0, L"147,haianhaibian3.bmp,0", true);
		RunTask(L"task_GuZhangDeYuanYinEnd", 0, L"", false);
		RunTask(L"task_HaiBianYuanZhuMingEnd", 0, L"", false);
		RunTask(L"moveTo_HaiBian3", 0, L"147,haianhaibian3.bmp,0", false);

	}
	else if (str_mapName == L"mapHaiBian3") {
		nXPath = RandomNumber(120, 125);
		RunTask(L"task_YiShiJieZhi", 0, L"", true);
		RunTask(L"task_YiShiJieZhiEnd", 0, L"", false);
		RunTask(L"task_SiRenHaiTanEnd", 0, L"10,haianhaibian2.bmp,0", false);
		RunTask(L"task_XunZhaoQianTIng", 0, L"146,map_QianHai1.bmp,0", false);

	}
	else if (str_mapName == L"map_QianHai1") {
		nXPath = 69;
		//taskPath = 69;
		RunTask(L"task_HeiSeBoLang", 0, L"", true);
		RunTask(L"task_YiSHiYouYongQuan", 0, L"", true);
		if (g_TaskName == L"task_HeiSeBoLangEnd") {
			strPath = L"148,map_QianHai2.bmp,0";
			if (movetoEX(strPath)) {
				for (size_t k = 0; k < 10; k++)
				{
					CString strMap = g_dm->FindPicS(0, 0, 470, 150, L"mapCaoCong3.bmp|mapCaoCong2.bmp|mapCaoCong1.bmp|mapDuJiaCun.bmp|mapHaiBian1.bmp|mapHaiBian2.bmp|mapHaiBian3.bmp|map_QianHai1.bmp|map_QianHai2.bmp|map_QianHai3.bmp|map_XiaoBoLang.bmp|map_XiaoBoLang2.bmp|map_DaBoLang.bmp", L"050505", 1, 0, &x, &y);
					if (strMap == L"mapDuJiaCun.bmp") {
						continue;
					}
					else {
						g_dm->FindPic(0, 0, 1000, 600, L"bagWnd.bmp", L"050505", 0.9, 0, &x, &y);
						if (x > 0) {//存在
							Sleep(500);

							long x1, y1;
							g_dm->FindPic(0, 0, 800, 600, L"wupinsuoxiao.bmp", L"050505", 0.9, 0, &x1, &y1);
							if (x1 > 0) {
								Sleep(500);
								g_dm->MoveTo(5, 5);
								Sleep(500);
								g_dm->MoveTo(x1 + RandomNumber(3, 8), y1 + RandomNumber(3, 8));
								Sleep(1000);
								g_dm->LeftClick();
								Sleep(1500);
							}
							g_dm->FindPic(0, 0, 800, 600, L"bagWnd.bmp", L"050505", 0.9, 0, &x, &y);
							g_dm->FindPic(0, 0, 800, 600, L"wupinWnd.bmp", L"050505", 0.9, 0, &x1, &y1);
							if (x1 == -1) {
								g_dm->MoveTo(5, 5);
								Sleep(500);
								g_dm->MoveTo(x - RandomNumber(15, 20), y + 30);
								Sleep(1000);
								g_dm->LeftClick();
							}


							Sleep(2000);
							g_dm->FindPic(0, 0, 1024, 700, L"backKaPian.bmp", L"050505", 0.9, 0, &x, &y);
							if (x > 0) {
								g_dm->MoveTo(5, 5);
								Sleep(500);
								g_dm->MoveTo(x + RandomNumber(5, 15), y + RandomNumber(5, 15));
								Sleep(1000);
								g_dm->LeftDoubleClick();
								Sleep(4000);
								g_dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"050505", 1, 0, &x, &y);
								if (x > 0) {
									g_dm->KeyPress(73);//关闭背包
									Sleep(2000);
									continue;
								}
							}
						}
						else {//不存在
							Sleep(500);
							g_dm->KeyPress(73);
							Sleep(500);
						}
					}

				}

			}
			g_TaskState = false;
		}

		g_dm->FindPic(176, 15, 1024, 311, L"task_YiSHiYouYongQuan1End.bmp|task_YiSHiYouYongQuan1_2End.bmp", L"050505", 1, 0, &x, &y);
		if (x > 0) {
			strPath = L"149,map_QianHai2.bmp,0";			   
			if (movetoEX(strPath)) {
				g_TaskState = true;
			}
		}

	}
	else if (str_mapName == L"map_QianHai2") {
		nXPath = 50;
		g_dm->FindPic(176, 15, 1024, 311, L"task_YiSHiYouYongQuan1End.bmp|task_YiSHiYouYongQuan2_1.bmp|task_YiSHiYouYongQuan2.bmp", L"050505", 1, 0, &x, &y);
		if (x > 0) {
			g_TaskState = true;
		}
		g_dm->FindPic(176, 15, 1024, 311, L"task_YiSHiYouYongQuan2End.bmp", L"050505", 1, 0, &x, &y);
		if (g_TaskName == L"task_YiSHiYouYongQuanEnd" || x>0) {
			nXPath = 50;
			g_TaskState = false;
		}
		if (g_TaskName == L"task_XinXianCaiLiao") {
			//taskPath = 50;
			strPath = L"148,xianhai3_MAP.bmp,0";
			if (movetoEX(strPath)) {
				g_TaskState = true;
			}
		}
	}
	else if (str_mapName == L"map_QianHai3") {
		nXPath = 25;
		RunTask(L"task_XinXianCaiLiaoEnd", 0, L"", false);
		RunTask(L"task_DiaoYuWangEnd", 0, L"", false);
		RunTask(L"task_DiaoYuWang", 0, L"", true);
		RunTask(L"task_BoLangJuanZhou", 0, L"148,map_XiaoBoLang.bmp,0", true);
		RunTask(L"task_HaiXingShuiLing", 0, L"148,map_XiaoBoLang.bmp,0|148,map_XiaoBoLang2.bmp,0", true);
		RunTask(L"task_HeiShuiFaYuanDi", 69, L"148,map_XiaoBoLang.bmp,0|148,map_XiaoBoLang2.bmp,0|146,map_DaBoLang.bmp,0", false);
	}
	else if (str_mapName == L"map_XiaoBoLang") {//小波浪1
		RunTask(L"task_BoLangJuanZhouEnd", 0, L"10,map_QianHai3.bmp,0", false);
	}

	if (str_mapName == L"map_XiaoBoLang2") {//小波浪2
		//RunTask(L"task_HaiXingShuiLingEnd", 0, L"146,map_DaBoLang.bmp,0", true);
		RunTask(L"task_HaiLuoShuiLing", 0, L"146,map_DaBoLang.bmp,0", true);
	}
	if (str_mapName == L"map_DaBoLang") {
		nXPath = 80;
		//RunTask(L"task_HaiXingShuiLingEnd", 0, L"", false);
		RunTask(L"task_HaiLuoShuiLing", 0, L"", true);
		RunTask(L"task_HaiLuoShuiLingEnd", 0, L"10,map_XiaoBoLang2.bmp,0|10,map_XiaoBoLang.bmp,0|10,map_QianHai3.bmp,0", false);
		RunTask(L"task_JingRanBuShiyzm", 0, L"", true);
		RunTask(L"task_YuanZhuMingEnd", 0, L"", false);
		if (g_TaskName == L"task_JinHaiAnHuiCheng") {
			for (size_t k = 0; k < 10; k++)
			{
				CString strMap = g_dm->FindPicS(0, 0, 470, 150, L"mapCaoCong3.bmp|mapCaoCong2.bmp|mapCaoCong1.bmp|mapDuJiaCun.bmp|mapHaiBian1.bmp|mapHaiBian2.bmp|mapHaiBian3.bmp|map_QianHai1.bmp|map_QianHai2.bmp|map_QianHai3.bmp|map_XiaoBoLang.bmp|map_XiaoBoLang2.bmp|map_DaBoLang.bmp", L"050505", 1, 0, &x, &y);
				if (strMap == L"mapDuJiaCun.bmp") {
					continue;
				}
				else {
					g_dm->FindPic(0, 0, 1000, 600, L"bagWnd.bmp", L"050505", 0.9, 0, &x, &y);
					if (x > 0) {//存在
						Sleep(500);

						long x1, y1;
						g_dm->FindPic(0, 0, 800, 600, L"wupinsuoxiao.bmp", L"050505", 0.9, 0, &x1, &y1);
						if (x1 > 0) {
							Sleep(500);
							g_dm->MoveTo(5, 5);
							Sleep(500);
							g_dm->MoveTo(x1 + RandomNumber(3, 8), y1 + RandomNumber(3, 8));
							Sleep(1000);
							g_dm->LeftClick();
							Sleep(1500);
						}
						g_dm->FindPic(0, 0, 800, 600, L"bagWnd.bmp", L"050505", 0.9, 0, &x, &y);
						g_dm->FindPic(0, 0, 800, 600, L"wupinWnd.bmp", L"050505", 0.9, 0, &x1, &y1);
						if (x1 == -1) {
							g_dm->MoveTo(5, 5);
							Sleep(500);
							g_dm->MoveTo(x - RandomNumber(15, 20), y + 30);
							Sleep(1000);
							g_dm->LeftClick();
						}


						Sleep(2000);
						g_dm->FindPic(0, 0, 1024, 700, L"backKaPian.bmp", L"050505", 0.9, 0, &x, &y);
						if (x > 0) {
							g_dm->MoveTo(5, 5);
							Sleep(500);
							g_dm->MoveTo(x + RandomNumber(5, 15), y + RandomNumber(5, 15));
							Sleep(1000);
							g_dm->LeftDoubleClick();
							Sleep(4000);
							g_dm->FindPic(0, 0, 1024, 700, L"bagWnd.bmp", L"050505", 1, 0, &x, &y);
							if (x > 0) {
								g_dm->KeyPress(73);//关闭背包
								Sleep(2000);
								continue;
							}
						}
					}
					else {//不存在
						Sleep(500);
						g_dm->KeyPress(73);
						Sleep(500);
					}
				}

			}
		}
	}
}


void RunTask(CString str_TaskName,int n_XPath,CString str_Path,bool b_Flag) {
	long x, y;
	g_dm->FindPic(0, 0, 1024, 500, L"task_WeiChiZhengJie.bmp",L"050505",1,0,&x,&y);
	if (x > 0) {
		g_TaskName = L"task_WeiChiZhengJie";
		str_Path = L"148,haianhaibian1.bmp,0";
	}
	if (g_TaskName == str_TaskName) {
		if (n_XPath != 0) {
			nXPath = n_XPath;
		}
		if (str_Path != L"") {
			MoveToMapEx(str_Path);
			//movetoEX(str_Path);
		}
		g_TaskState = b_Flag;
	}
}


void moveRandGong() {
	// TODO: 在此添加控件通知处理程序代码
	long x, y;
	CString strKey;

	int nkey = 37;

	g_dm->FindPic(0, 0, m_mapArr[2], m_mapArr[3], L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);

	if (x > m_mapArr[2] - 40)
	{
		g_dm->KeyUp(39);
		nkey = 37;
	}
	if (x < m_mapArr[0] + 40) {
		g_dm->KeyUp(37);
		nkey = 39;
	}
	g_dm->KeyUp(37);
	RandomNumber(300, 900);
	g_dm->KeyUp(39);
	RandomNumber(300, 900);
	g_dm->KeyDown(nkey);

	for (size_t i = 0; i < 10; i++)
	{

		if (i % 6 == 0) {
			g_dm->delay(RandomNumber(170, 280));
			g_dm->KeyDown(46);
			g_dm->delay(RandomNumber(70, 180));
			g_dm->KeyUp(46);
		}
		if (i % 3 == 0) {
			g_dm->delay(RandomNumber(370, 480));
			JumpDown();
		}


		g_dm->FindPic(0, 0, m_mapArr[2], m_mapArr[3], L"localTag.bmp|localTag1.bmp|localTag2.bmp|localTag3.bmp|localTag4.bmp", L"050505", 0.9, 0, &x, &y);
		if (x > m_mapArr[2] - 40)
		{
			g_dm->KeyUp(39);
			g_dm->delay(RandomNumber(60, 150));
			nkey = 37;
			g_dm->KeyDown(nkey);
		}
		if (x < m_mapArr[0] + 40) {
			g_dm->KeyUp(37);
			g_dm->delay(RandomNumber(60, 150));
			nkey = 39;
			g_dm->KeyDown(nkey);
		}
		g_dm->delay(RandomNumber(200, 500));
		g_dm->KeyDown(18);
		g_dm->delay(RandomNumber(60, 150));
		g_dm->KeyUp(18);
		g_dm->delay(RandomNumber(50, 150));
		g_dm->KeyDown(16);
		g_dm->delay(RandomNumber(70, 180));
		g_dm->KeyUp(16);
		g_dm->delay(RandomNumber(200, 400));

		g_dm->delay(RandomNumber(250, 350));
		g_dm->KeyDown(16);
		g_dm->delay(RandomNumber(70, 180));
		g_dm->KeyUp(16);
		g_dm->delay(RandomNumber(200, 400));
	}

}
